Java – ant contains external jar
•
Java
I want to include an external jar. Jar in my java project I'm using ants External Jar is located in the Lib folder My build XML looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<project>
<path id="classpath">
<fileset dir="lib" includes="**/*.jar"/>
</path>
<target name="clean">
<delete dir="build"/>
</target>
<target name="compile">
<mkdir dir="build"/>
<javac srcdir="src" destdir="build" classpathref="classpath" />
</target>
<target name="jar">
<mkdir dir="trash"/>
<jar destfile="trash/test.jar" basedir="build">
<zipgroupfileset dir="lib" includes="**/*.jar"/>
<manifest>
<attribute name="Main-Class" value="com.Test"/>
</manifest>
</jar>
</target>
<target name="run">
<java jar="trash/test.jar" fork="true"/>
</target>
</project>
But it doesn't work When I want to from the outside When importing something from jar, an error occurs after the command ant compile: package com Something doesn't exist What should I edit to make it work?
Exact error:
Compiling 23 source files to xy/build xy/src/com/Test.java:5: package com.thoughtworks.xstream does not exist import com.thoughtworks.xstream.*; ^ 1 error
Solution
You should try to include no attributes:
<fileset dir="lib" />
In the jar section, you include the following classes:
<zipgroupfileset includes="*.jar" dir="lib"/>
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
