帮助处理 ant 文件 - Java 任务的类路径 [英] help with ant file - classpath for Java task

查看:32
本文介绍了帮助处理 ant 文件 - Java 任务的类路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 Ant 构建文件,并尝试使用目标运行"来执行程序.

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"

非常感谢任何帮助.谢谢

Any help is greatly appreciated. Thanks

推荐答案

来自 java 任务文档:

From the java task docs:

使用 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>

如果要调用 jar,则需要在构建它时在清单中设置类路径条目.看看 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆