与Ant文件帮助 - 类路径中的Java任务 [英] help with ant file - classpath for Java task
问题描述
我有蚂蚁以下构建文件,并尝试使用执行该程序运行目标。
I have the below build file for Ant and trying to use the target 'run' for executing the program.
<property name="springjar" location="E:/Tools/spring-30/dist/" />
<property name="logjar" location="E:/Tools/commons-logging-1.1.1/" />
<patternset id="jar.files"><include name="**/*.jar"/></patternset>
<path id="springlearn.classpath">
<fileset dir="${springjar}"><patternset refid="jar.files"/></fileset>
<fileset dir="${logjar}"><patternset refid="jar.files"/></fileset>
</path>
<target name="run" depends="dist" description="Execute the Java Program">
<java dir ="." fork="true" jar="dist\app.jar" classpathref ="springlearn.classpath">
</java>
</target>
使用相同的classpathref,我能够成功地编译和放大器;创建JAR,但使用目标运行时,我得到下面的错误
Using the same classpathref, I am able to successfully compile & create the jar, but when use the target run, I get the below error
java.lang.NoClassDefFoundError: org/springframework/core/io/Resource
Caused by: java.lang.ClassNotFoundException: org.springframework.core.io.Resource
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:289)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
异常线程main
Exception in thread "main"
任何帮助是极大AP preciated。谢谢
Any help is greatly appreciated. Thanks
推荐答案
从 的java
任务文档:
在使用jar属性,所有的类路径设置根据的 Sun的规范。
When using the jar attribute, all classpath settings are ignored according to Sun's specification.
所以,你设置的路径并不被看的。
So the classpath you set up isn't being looked at at all.
您可以添加 DIST / app.jar
到类路径中并调用主类直接:
You could add dist/app.jar
to your classpath and call the main class direct:
<java dir ="." fork="true" classname="com.yourdomain.YourMainClass">
<classpath>
<path refid="springlearn.classpath" />
<pathelement location="dist\app.jar" />
</classpath>
</java>
如果您要拨打的罐子,你需要建立一个类路径条目在清单中,当你构建它。看一看在 pathconvert 的任务,它可能是有益的。
If you want to call the jar, you'll need to set up a classpath entry in the manifest when you build it. Have a look at the pathconvert task, it could be useful.
这篇关于与Ant文件帮助 - 类路径中的Java任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!