Quartz 1.6 and OC4J Windows Fix

I was recently getting Quartz 1.6 setup to run in a application running on a OC4J server. The issue raised its ugly head when the Quartz server was trying to locate and load the quartz_jobs.xml file.

The internal OC4J Application Server running in JDeveloper 10.1.3.3 gave me the following error:


2008-04-11 16:39:07,939 ERROR (org.quartz.plugins.xml.JobInitializationPlugin:398) - Error scheduling jobs: no protocol: /C:/affiliateweb_p3/affiliateweb/classes/quartz_jobs.xml
java.net.MalformedURLException: no protocol: /C:/affiliateweb_p3/affiliateweb/classes/quartz_jobs.xml

What is interesting about this issue is that the file is located in “C:\affiliateweb_p3\affiliateweb\classes\quartz_jobs.xml” but as you notice in the error message there is a forward slash “/” before the “C:”. This is what is causing the issue, because that is not a valid file path in Windows.

To help figure out how to fix this issue I decided to go and look at the JobInitializationPlugin class to see what was happening under the hood. What I found that the issue was in a inner class inside of JobInitializationPlugin called JobFile.

In the JobFile inner class there is a initialization method that takes the file name passed in through the constructor, and see’s if it can be located successfully. The code would pass in the file name of quartz_jobs.xml as a String and create a java.net.URL from the location of the file. This is where things get messed up. The URL value is used to set some file information and other string parameters with the URL.getPath() method. This method returns the path without the file:/ appended to it. But in windows it only removes the ~file: part of the host leaving the /C:/ left on the path.

To fix this what I did was just get the URL.toString() value. This returned me the file:/c:/... file location which allows all functions to successfully find the quartz_jobs.xml file correctly. The quartz JobInitializationPlugin class was very easy to change. The code already had a change commented out that read “we need jdk1.3 compatibility, so we abandon this code...”. I uncommented out this code in the quartz source and changed it to be the following:



// we need jdk 1.3 compatibility, so we abandon this code...
try {
furl = URLDecoder.decode(url.toString(), “UTF-8”);
} catch (UnsupportedEncodingException e) {
furl = url.toString();
}
// furl = URLDecoder.decode(url.getPath());


You will also see in the code above that I have commented out the old furl = URLDecoder.decode..... statement. This is not used anymore because of my fix.

I found that this was very easy to implement as all I had to do was copy the source code from quartz into my project, change the package name, make the simple code change, and reference it in the quartz.properties file like so:


org.quartz.plugin.jobInitializer.class = edu.unc.its.as.affiliate.quartz.JobInitializationPlugin

If you would like to download my code please get it from here . I hope that this helps some people out. I have not tried to run this JobInitializationPlugin code on a OC4J unix machine or another server, but I don’t see why it would not work.

Posted on Apr 15, 2008 by Mike Jennings in Java | 0 Comments | Permalink