使用 Ant 使用 log4j 运行任务时出现问题
我的 java 应用程序使用 log4j 进行日志记录。使用 ant 项目成功构建,但我无法运行它。我得到的错误是
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/Log
.........
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.Log
我的类路径包含 log4j jar。
[echo] ..../apache-log4j-1.2.15/log4j-1.2.15.jar: .....
我的ant版本是1.7.1。我缺少什么?
[编辑] 我的应用程序正在引用另一个需要公共日志记录 jar 的项目。因此,我尝试创建引用项目的可执行 jar,以便继承所有依赖项。创建可执行 jar 的 ant 任务如下:
<target name="executablejar" depends="compile">
<delete file="${dist}/app.jar" />
<javac debug="true" srcdir="${src}" destdir="${classes}" classpath="${javac.classpath}"/>
<copy todir="classes" flatten="true">
<path>
<pathelement path="${javac.classpath}"/>
</path>
</copy>
<jar jarfile="${dist}/app.jar" basedir="${classes}" />
</target>
但是错误仍然存在。我是否正确创建了可执行 jar?
My java application uses log4j for logging. Using ant the project builds successfully, but I am unable to run it. The error I get is
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/Log
.........
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.Log
My classpath contains the log4j jar.
[echo] ..../apache-log4j-1.2.15/log4j-1.2.15.jar: .....
My ant version is 1.7.1. What am I missing?
[Edit] My application is referencing another project which required the commons logging jar. So I tried creating an executable jar of the referenced project so that all the dependencies are carried over. The ant task to create the executable jar is as follows:
<target name="executablejar" depends="compile">
<delete file="${dist}/app.jar" />
<javac debug="true" srcdir="${src}" destdir="${classes}" classpath="${javac.classpath}"/>
<copy todir="classes" flatten="true">
<path>
<pathelement path="${javac.classpath}"/>
</path>
</copy>
<jar jarfile="${dist}/app.jar" basedir="${classes}" />
</target>
However the error still persists. Am I creating the executable jar correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能无意中从 org.apache.commons.logging 导入了一个类,现在,正如您所料,JVM 希望在运行时在您的类路径中找到类定义。
我建议在您的代码中查找 commons-logging 包的用法。
You may have inadvertently imported a class from
org.apache.commons.logging
and now, as you might expect, the JVM is expecting to find the class definition on your classpath at runtime.I'd recommend looking for usages of the commons-logging package in your code.
您将 apache commons 日志记录 添加到您的类路径中。 org.apache.commons.logging 包不是 log4j 的一部分。
You'll have add apache commons logging to your classpath. The package
org.apache.commons.logging
is not part of log4j.