Senin, 23 Agustus 2010

Java JDOM Jar Issue Cannot Find Symbol

Q: I am using the latest Java's JDOM library to compile some old code that uses JDOM, but I am getting "cannot find symbol" error. How do I resolve it?

Specifically the error you are getting looks like the following:

SomeJavaFileThatUsesJdom.java:14: cannot find symbol
symbol : constructor XMLOutputter(java.lang.String,boolean)
location: class org.jdom.output.XMLOutputter
private XMLOutputter xout = new XMLOutputter(" ", true);


The cause of the error is that the JDOM jar you are using is new and does not support this constructor. This really sucks because you'd think the newer version of some Java library should be backwards compatible. Anyway you just need to find the version that supports XMLOutputter constructor that accepts a String as the first argument and a Boolean as the second argument. I'll go through the steps to do this but if you just want to know which JDOM jar solves this issue then scroll down to find it. Questions?

To find the version of JDOM classes that fixes the error, you go to JDOM's archive binary page at http://www.jdom.org/dist/binary/archive/ and download and try each version during compilation. At the time of writing here's a list of available jars:

jdom-1.0.tar.gz
jdom-1.1.tar.gz
jdom-b3.tar.gz
jdom-b6.tar.gz
jdom-b7.tar.gz
jdom-b8.tar.gz
jdom-b9.tar.gz
jdom-b10.tar.gz


Download each one and untar or unzip it and identify the jar location. In older versions it should be named jdom-.jar located in jdom/ folder. In newer versions it should be named jdom.jar located in jdom-/build/ folder. Use '-cp' argument option when compiling the Java file to make javac use a specific jar (suppose the jar location is c:\jdom\jdom-b3.jar):

javac -cp c:\jdom\jdom-b3.jar SomeJavaFileThatUsesJdom.java

And see if you are still getting the same error.

To save you trouble, I tried them all and found that jdom-b6.jar fixes the issue:

admin@one-minute-info$ javac -cp jdom-b6.jar SomeJavaFileThatUsesJdom.java
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
admin@one-minute-info$


As an alternative, you can modify your code to use the version of the jar you are using but it's highly not recommended. You'd end up having to debug issues resulted from the differences between the two versions of the jar. If you are feeling adventurous and living on the edge knock yourself out!

Questions? Let me know!

0 komentar:

 
support by: infomediaku.com