从 Ant 启动 tomcat 7 时出现 java.lang.NoClassDefFoundError
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20536532/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.lang.NoClassDefFoundError while starting tomcat 7 from Ant
提问by ivstas
My goal is to start tomcat using Ant. Here is my script:
我的目标是使用 Ant 启动 tomcat。这是我的脚本:
<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.run(URLClassLoader.java:366)
at java.net.URLClassLoader.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
!
我已经检查过:org.apache.juli.logging.LogFactory
课程出现在tomcat-juli.jar
!
What could be wrong?
可能有什么问题?
采纳答案by ivstas
For some unknown weird reasons tomcat doesn't start in my system even when I launch it from command line using java -jar
command.
由于一些未知的奇怪原因,即使我使用java -jar
命令从命令行启动它,tomcat 也不会在我的系统中启动。
However, I managed to startit using java -cp "bin\bootstrap.jar;bin\tomcat-juli.jar" org.apache.catalina.startup.Bootstrap
command, executed from tomcat.home
directory.
但是,我设法使用java -cp "bin\bootstrap.jar;bin\tomcat-juli.jar" org.apache.catalina.startup.Bootstrap
从tomcat.home
目录执行的命令启动它。
The code in ant which does the same:
ant 中执行相同操作的代码:
<exec executable="java" dir="${tomcat.home}">
<arg line="-cp bin\bootstrap.jar;bin\tomcat-juli.jar"/>
<arg value="org.apache.catalina.startup.Bootstrap"/>
</exec>
回答by Santosh
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.
查看startup.sh
tomcat的批处理文件或shell脚本。除了bootstrap.jar
. 检查setclasspath.sh
。它在类路径中设置了所有 jars。
Other more cleanapproach would be to invoke startup.sh
script from ant. This will do everything for what it takes to start Tomcat Server.
其他更干净的方法是startup.sh
从 ant调用脚本。这将完成启动 Tomcat 服务器所需的一切工作。
回答by Chip McCormick
If you want to stick with using catalina, the proper method is to add \setenv.bat with contents like:
如果你想坚持使用 catalina,正确的方法是添加 \setenv.bat 的内容如下:
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
我通过阅读 catalina.bat 发现了这一点。有人可能想用适当的 Tomcat 文档更新它