grexx
asked on
[Mac OSX] Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tools/ant/Main
I'm trying to build an example servlet from the FOP application (http://xml.apache.org/fop) on a Mac OS X 10.3. I've set the JAVA_HOME variable to /library/java/home. I've copied the Ant-directory to /library/java/extensions, where the Fop directory is as well. I've set the ANT_HOME variable to the proper folder as well, although I don't know if this is necessary. Now if I run build.sh, I get the following error.
Building with classpath /Library/Java/Home/lib/too ls.jar:/Li brary/Java /Home/lib/ classes.zi p:../../li b/ ant-1.5.1.jar:../../lib/xm l-apis.jar :../../lib /xercesImp l-2.2.1.ja r:../../li b/xalan-2. 4.1.jar
Starting Ant...
Exception in thread "main" java.lang.NoClassDefFoundE rror: org/apache/tools/ant/Main
I suppose this has to do with Ant, or with the classpath variable. If I run "env" in the terminal, I don't see a classpath variable. Furthermore, I've installed Ant 1.6.2 and I see a reference to 1.5.1, so that could be the problem?!
I've found the following tip to set the classpath (%SET CLASSPATH = ${CLASSPATH}:.), but when I run it, it says "undefined variable". If I use a hard path, it says "too many arguments".
Then I'm not sure what path I should use?! Should I use the lib-folder of Ant? I have Xerces, Fop and Xalan as well, do I add those too?
Building with classpath /Library/Java/Home/lib/too
Starting Ant...
Exception in thread "main" java.lang.NoClassDefFoundE
I suppose this has to do with Ant, or with the classpath variable. If I run "env" in the terminal, I don't see a classpath variable. Furthermore, I've installed Ant 1.6.2 and I see a reference to 1.5.1, so that could be the problem?!
I've found the following tip to set the classpath (%SET CLASSPATH = ${CLASSPATH}:.), but when I run it, it says "undefined variable". If I use a hard path, it says "too many arguments".
Then I'm not sure what path I should use?! Should I use the lib-folder of Ant? I have Xerces, Fop and Xalan as well, do I add those too?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
$JAVA_HOME/lib/classes.zip belongs to java < 1.3
If you have Java > 1.3 (as it seems) then it is called rt.jar (or dt.jar) and there is no need to include it in the classpath.
$JAVA_HOME/lib/tools.jar should be found directly under $JAVA_HOME/lib (but not having it should not cause this problem).
Are you sure that $ANT_HOME is set correctly and that $ANT_HOME/bin is in your PATH?
What is build.sh and how do you invoke ant?
If you have Java > 1.3 (as it seems) then it is called rt.jar (or dt.jar) and there is no need to include it in the classpath.
$JAVA_HOME/lib/tools.jar should be found directly under $JAVA_HOME/lib (but not having it should not cause this problem).
Are you sure that $ANT_HOME is set correctly and that $ANT_HOME/bin is in your PATH?
What is build.sh and how do you invoke ant?
ASKER
Build.sh runs a build.xml script (using Ant) to compile a servlet. The servlet is in the examples folder of the FOP application.
In build.sh, I removed the lines that referred to classes.zip and tools.jar. Then I've changed the classpath using JAVA_EXT as you can see below. If I run build.sh (in the terminal in the directory itself: ./build.sh), it gives the following error.
% ./build.sh
Fop Build System
----------------
Ant home: /Library/Java/Extensions/a pache-ant- 1.6.2
Java home: /Library/Java/Home
Building with classpath :
/Library/Java/Extensions/a pache-ant- 1.6.2/lib/ ant.jar:
/Library/Java/Extensions/f op-0.20.5/ lib/xml-ap is.jar:
/Library/Java/Extensions/f op-0.20.5/ lib/xerces Impl-2.2.1 .jar:
/Library/Java/Extensions/f op-0.20.5/ lib/xalan- 2.4.1.jar
Starting Ant...
Exception in thread "main" java.lang.NoClassDefFoundE rror: org/apache/tools/ant/launc h/AntMain
at java.lang.ClassLoader.defi neClass0(N ative Method)
at java.lang.ClassLoader.defi neClass(Cl assLoader. java:539)
at java.security.SecureClassL oader.defi neClass(Se cureClassL oader.java :123)
at java.net.URLClassLoader.de fineClass( URLClassLo ader.java: 251)
at java.net.URLClassLoader.ac cess$100(U RLClassLoa der.java:5 5)
at java.net.URLClassLoader$1. run(URLCla ssLoader.j ava:194)
at java.security.AccessContro ller.doPri vileged(Na tive Method)
at java.net.URLClassLoader.fi ndClass(UR LClassLoad er.java:18 7)
at java.lang.ClassLoader.load Class(Clas sLoader.ja va:289)
at sun.misc.Launcher$AppClass Loader.loa dClass(Lau ncher.java :274)
at java.lang.ClassLoader.load Class(Clas sLoader.ja va:235)
at java.lang.ClassLoader.load ClassInter nal(ClassL oader.java :302)
========================== ========== ========== =
Below the contents of the build.sh file
========================== ========== ========== =
echo Ant home: $ANT_HOME
echo Java home: $JAVA_HOME
JAVA_EXT=/Library/Java/Ext ensions
# ANT_HOME=/Library/Java/Ext ensions/ap ache-ant-1 .6.2
# LOCALCLASSPATH=$JAVA_HOME/ lib/tools. jar:$JAVA_ HOME/lib/c lasses.zip
LOCALCLASSPATH=$LOCALCLASS PATH:$ANT_ HOME/lib/a nt.jar
LOCALCLASSPATH=$LOCALCLASS PATH:$JAVA _EXT/fop-0 .20.5/lib/ xml-apis.j ar
LOCALCLASSPATH=$LOCALCLASS PATH:$JAVA _EXT/fop-0 .20.5/lib/ xercesImpl -2.2.1.jar
LOCALCLASSPATH=$LOCALCLASS PATH:$JAVA _EXT/fop-0 .20.5/lib/ xalan-2.4. 1.jar
echo Building with classpath $LOCALCLASSPATH
echo Starting Ant...
$JAVA_HOME/bin/java -Dant.home=$ANT_HOME -classpath "$LOCALCLASSPATH" org.apache.tools.ant.Main $*
In build.sh, I removed the lines that referred to classes.zip and tools.jar. Then I've changed the classpath using JAVA_EXT as you can see below. If I run build.sh (in the terminal in the directory itself: ./build.sh), it gives the following error.
% ./build.sh
Fop Build System
----------------
Ant home: /Library/Java/Extensions/a
Java home: /Library/Java/Home
Building with classpath :
/Library/Java/Extensions/a
/Library/Java/Extensions/f
/Library/Java/Extensions/f
/Library/Java/Extensions/f
Starting Ant...
Exception in thread "main" java.lang.NoClassDefFoundE
at java.lang.ClassLoader.defi
at java.lang.ClassLoader.defi
at java.security.SecureClassL
at java.net.URLClassLoader.de
at java.net.URLClassLoader.ac
at java.net.URLClassLoader$1.
at java.security.AccessContro
at java.net.URLClassLoader.fi
at java.lang.ClassLoader.load
at sun.misc.Launcher$AppClass
at java.lang.ClassLoader.load
at java.lang.ClassLoader.load
==========================
Below the contents of the build.sh file
==========================
echo Ant home: $ANT_HOME
echo Java home: $JAVA_HOME
JAVA_EXT=/Library/Java/Ext
# ANT_HOME=/Library/Java/Ext
# LOCALCLASSPATH=$JAVA_HOME/
LOCALCLASSPATH=$LOCALCLASS
LOCALCLASSPATH=$LOCALCLASS
LOCALCLASSPATH=$LOCALCLASS
LOCALCLASSPATH=$LOCALCLASS
echo Building with classpath $LOCALCLASSPATH
echo Starting Ant...
$JAVA_HOME/bin/java -Dant.home=$ANT_HOME -classpath "$LOCALCLASSPATH" org.apache.tools.ant.Main $*
The missing jar is ant-launcher.jar (should be found at $ANT_HOME/lib/) which you will need to include in your CLASSPATH.
But why are you launching ant this way and not using one of its scripts? (as I specfied before).
Once you get over this missing class problem (by adding $ANT_HOME/lib/ant-launcher .jar to your classpath) you might find other classes
missing (from $ANT_HOME/lib/*.jar)
But why are you launching ant this way and not using one of its scripts? (as I specfied before).
Once you get over this missing class problem (by adding $ANT_HOME/lib/ant-launcher
missing (from $ANT_HOME/lib/*.jar)
ASKER
Why am I launching Ant this way? Compiling stuff like this is not my daily job. I have done things like this before, although I can't remember how I did it then. I believe in the manual of fop it said something about the build.sh file, so I tried to run it. That's the reason. But I suppose you say there is a better way to do this?
Yes, though the fix I provided you above should solve that problem.
Ant comes with scripts to run it (under $ANT_HOME/bin).
After setting your classpath (in your build.sh) invoke of one of those scripts instead of
runing ant it directly via java.
Ant comes with scripts to run it (under $ANT_HOME/bin).
After setting your classpath (in your build.sh) invoke of one of those scripts instead of
runing ant it directly via java.
ASKER
I finally got it. I used $ANT_HOME/bin/ant -f /{servlet-location}/build. xml. Thanks!
:-)
ASKER
LOCALCLASSPATH=$JAVA_HOME/
If I look for these files (tools.jar and classes.zip), they are not present. The file list for /library/java/home/lib is:
Xusage.txt
audio/
client_jvm.cfg
cmm/
content-types.properties
dt.jar
endorsed/
ext/
flavormap.properties
fonts/
im/
images/
ir.idl
jaws.jar
jce.jar
jvm.cfg
jvm.hprof.txt
logging.properties
netscape.jar
orb.idl
psfont.properties.ja
psfontj2d.properties
security/
server_jvm.cfg
swing.properties
tzmappings
zi/