My goal is to start tomcat using Ant. Here is my script:
<target name="tomcat-start">
<java jar="${tomcat.home}/bin/bootstrap.jar" fork="true" dir="${tomcat.home}">
<classpath>
<fileset dir="${tomcat.home}/bin">
<include name="bootstrap.jar"/>
<include name="tomcat-juli.jar"/>
</fileset>
</classpath>
<jvmarg value="-Dcatalina.home=${tomcat.home}"/>
</java>
</target>
After script execution I receive this output:
java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory
at org.apache.catalina.startup.Bootstrap.<clinit>(Bootstrap.java:60)
Caused by: java.lang.ClassNotFoundException: org.apache.juli.logging.LogFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 1 more
Exception in thread "main"
Java Result: 1
I've checked: org.apache.juli.logging.LogFactory
class is presented in tomcat-juli.jar
!
What could be wrong?
You can fix NoClassDefFoundError error by checking following: Check the exception stack trace to know exactly which class throw the error and which is the class not found by java.
NoClassDefFoundError, which means the Class Loader file responsible for dynamically loading classes can not find the . class file. So to remove this error, you should set your classpath to the location where your Class Loader is present. Hope it helps!!
NoClassDefFoundError is a common error in Java that occurs if a ClassLoader cannot find a particular class in the classpath while trying to load it. The Exception in thread "main" suggests that this error has occurred in the main thread, the thread which is responsible for running the Java application.
For some unknown weird reasons tomcat doesn't start in my system even when I launch it from command line using java -jar
command.
However, I managed to start it using java -cp "bin\bootstrap.jar;bin\tomcat-juli.jar" org.apache.catalina.startup.Bootstrap
command, executed from tomcat.home
directory.
The code in ant which does the same:
<exec executable="java" dir="${tomcat.home}">
<arg line="-cp bin\bootstrap.jar;bin\tomcat-juli.jar"/>
<arg value="org.apache.catalina.startup.Bootstrap"/>
</exec>
If you want to stick with using catalina, the proper method is to add \setenv.bat with contents like:
set CLASSPATH=D:\tomcat\apache-tomcat-7.0.42\bin\bootstrap.jar;D:\tomcat\apache-tomcat-7.0.42\bin\tomcat-juli.jar
I discovered that by reading catalina.bat. Someone might want to update this with the proper Tomcat doc
Check out the startup.sh
batch file or shell script of tomcat. It has bunch of other files apart from bootstrap.jar
. check setclasspath.sh
. It has all jars are being set in class path.
Other more clean approach would be to invoke startup.sh
script from ant. This will do everything for what it takes to start Tomcat Server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With