简体   繁体   English

如何在 ant 中正确设置类路径?

[英]How to set classpath in ant correctly?

I have my single dependency on path projectRoot/lib/jsoup.jar .我对路径projectRoot/lib/jsoup.jar有我的单一依赖。

My build.xml is simple:我的 build.xml 很简单:

<project name="Ant-Demo" default="main" basedir=".">

    <property name="src.dir" value="src" />
    <property name="build.dir" value="buildDirectory" />
    <property name="dist.dir" value="dist" />
    <property name="docs.dir" value="docs" />
    <property name="lib.dir" value="lib" />

    <path id="build.classpath">
        <pathelement location="lib/jsoup-1.7.3.jar"/>
    </path>

    <target name="compile" depends="clean,makedir">
        <javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="build.classpath" />
    </target>

    <target name="jar" depends="compile">
    <jar destfile="${dist.dir}/AntDemo,jar" basedir="${build.dir}">
        <manifest>
            <attribute name="Main-Class" value="ant.test" />
        </manifest>
    </jar>
</target>
    ........................................... 

This doesn't work, because jsoup.jar is not included in final AntDemo.jar.这不起作用,因为 jsoup.jar 未包含在最终的 AntDemo.jar 中。

EDIT When compile target is running the output has warning:编辑当编译目标运行时,输出有警告:

compile:
    [javac] D:\Software\es_ws\AntDemo\build.xml:30: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
    [javac] Compiling 2 source files to D:\Software\es_ws\AntDemo\buildDirectory

What does this warning mean?这个警告是什么意思?

Thank you!谢谢!

If you need that the content of jsoup.jar is included on your AntDemo.jar you can do it on several ways.如果您需要将 jsoup.jar 的内容包含在您的AntDemo.jar 中,您可以通过多种方式实现。 My suggestion is use this solution:我的建议是使用这个解决方案:

<jar destfile="${dist.dir}/AntDemo.jar" >
    <manifest>
        <attribute name="Main-Class" value="ant.test" />
    </manifest>
    <fileset dir="${build.dir}" />
    <zipfileset includes="**/*.class" src="lib/jsoup-1.7.3.jar" />
</jar>

When you compile classes and specify a classpath, the classes and other resources in that javac classpath don't get copied over to the destination, in ant or in typical command line javac .当您编译类并指定类路径时,该javac类路径中的类和其他资源不会复制到目标,在 ant 或典型的命令行javac You need to copy them over manually, or in ant with a copy or other means.您需要手动复制它们,或者使用copy或其他方式在 ant 中复制它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM