使用 Ant 使用 log4j 运行任务时出现问题

发布于 2024-09-26 15:47:07 字数 1067 浏览 0 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柏林苍穹下 2024-10-03 15:47:07

您可能无意中从 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.

蓦然回首 2024-10-03 15:47:07

您将 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文