【发布时间】:2011-10-10 15:08:04
【问题描述】:
我正在尝试将 Log4j 添加到我在 Ant 中的项目的类路径中,这会创建一个可执行的 JAR,但它似乎没有被正确添加。
这是我的 Ant 构建脚本的 path 组件:
<path id="classpath.compile">
<fileset dir="${dir.myLibs}">
<include name="**/*.jar"/>
</fileset>
<pathelement location="${dir.webContent}/WEB-INF/lib/log4j.jar" />
</path>
编译目标如下:
<target name="-compile">
<javac destdir="${dir.binaries}" source="1.6" target="1.6" debug="true" includeantruntime="false">
<src path="${dir.source}"/>
<classpath refid="classpath.compile"/>
</javac>
</target>
创建 JAR 的目标:
<target name="-createJar" >
<jar jarfile="${path.jarFile}"
manifest="${dir.source}\META-INF\MANIFEST.MF">
<fileset dir="${dir.binaries}" casesensitive="yes">
<exclude name="**/*.java"/>
</fileset>
</jar>
</target>
最后,MANIFEST.MF:
Manifest-Version: 1.0
Class-Path: ../../../WebContent/WEB-INF/lib/log4j.jar (what is this pathing relative to?)
Main-Class: foo.Bar
创建了 JAR,但是当我执行它时,我得到:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger...
关于我做错了什么有什么想法吗?
【问题讨论】:
-
是 MANIFEST.MF 中的类路径声明还是运行时命令行中的 log4j 路径?
-
@highlycaffeinated:我已经在上面添加了我的 MANIFEST.MF。