ant 文件帮助 - Java 任务的类路径
我有下面的 Ant 构建文件,并尝试使用目标“运行”来执行程序。
<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,但是当使用目标运行时,我收到以下错误
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)
Exception in thread "main"
非常感谢任何帮助。谢谢
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>
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)
Exception in thread "main"
Any help is greatly appreciated. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个适合我的通用 Ant build.xml。看看它是否也能帮助你:
Here's a generic Ant build.xml that works well for me. See if it can help you as well:
来自
java
任务文档:所以你设置的类路径根本不会被查看。
您可以将
dist/app.jar
添加到您的类路径中并直接调用主类:如果您想调用该 jar,则需要在构建它时在清单中设置一个类路径条目。看看 pathconvert 任务,它可能很有用。
From the
java
task docs:So the classpath you set up isn't being looked at at all.
You could add
dist/app.jar
to your classpath and call the main class direct: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.