我尝试从 ant 运行我的应用程序,该应用程序正在使用 log4j jar 我现在有这个 ant 任务:
<property name="main-class" value="com.controller.core.Controller"/>
<target name="dist"
description="generate the distribution" >
<jar jarfile="${dist}/lib/controller.jar" basedir="${build}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
</manifest>
</jar>
</target>
<path id="class.path">
<fileset dir="..\lib">
<include name="**/*.jar" />
</fileset>
</path>
<target name="run">
<java jar="${dist}/lib/controller.jar" fork="true" >
<classpath refid="class.path" />
<classpath>
<path location="../lib/misc"/>
</classpath>
</java>
</target>
或者我什至给了它完整的路径,但仍然是同样的错误
<target name="run">
<java jar="${dist}/lib/controller.jar" fork="true" >
<classpath>
<path refid="test.classpath"/>
<path location="d:\dev\svn\trunk\lib\misc\log4j.jar"/>
</classpath>
</java>
</target>
log4j 在 ../lib/misc 路径中。但我仍然收到此错误:
run:
[java] java.lang.NoClassDefFoundError: org/apache/log4j/Logger
[java] at com.controller.core.Controller.<clinit>(Unknown Source)
[java] Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
[java] at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
[java] at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
[java] at java.security.AccessController.doPrivileged(Native Method)
[java] at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
[java] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
[java] ... 1 more
[java] Exception in thread "main"
[java] Java Result: 1
现在,当我使用 -v 标志运行 ant 时,它给了我这个消息:
[java] When using 'jar' attribute classpath-settings are ignored. See the manual for more information.
[java] Executing 'c:\Program Files (x86)\Java\jdk1.7.0_05\jre\bin\java.exe' with arguments:
[java] '-classpath'
[java] 'd:\dev\svn\trunk\lib\misc\log4j.jar'
[java] '-jar'
[java] 'D:\dev\svn\trunk\controller\dist\lib\controller.jar'
我在这里想念什么?