How to include external libraries in Ant build.xml file?

China☆狼群 提交于 2019-12-01 04:38:25
Java-Programmer

Replacing classes.dir=${build.dir}/classes with classes.dir=build/classes and jar.dir=${build.dir}/jar with jar.dir=build/jar from your build.properties file will work.

Please edit target jar as follows. I am sure it will work.

<target name="jar" depends="compile">

<delete dir="${jar.dir}"/>
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/${app.name}-${app.version}.jar" basedir="${classes.dir}">
  <manifest>
    <attribute name="Class-Path" value="${lib.dir}"/>
    <attribute name="Main-Class" value="${main.class}"/>
  </manifest>
   <zipgroupfileset  dir="${lib.dir}"/>

</jar>

I see that you have been trying to set your classpath for the <java> task.

Have you tried:

<java jar="${jar.dir}/${app.name}-${app.version}.jar" fork="true">
  <classpath refid="classpath" />
</java>

EDIT: double check the values in your properties file. Do you have trailing spaces for the value of lib.dir or jar.dir?

http://ant.apache.org/faq.html#properties-not-trimmed

ant failed to build my program via javac even when I put the needed jars in an external build.properties file and reference them by pathelement or classpath refid.

When ant loads properties from an external file it doesn't touch the value of properties, trailing blanks will not be trimmed for example.

If the value represents a file path, like a jar needed to compile, the task which requires the value, javac for example would fail to compile since it can't find the file due to trailing spaces.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!