我想将外部jar包含到我的java项目中。我正在使用蚂蚁。外部.jar位于文件夹lib中。我的build.xml看起来像这样:Ant包含外部.jar
<?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>
但它不起作用。当我想从外部.jar导入某些内容时,在命令ant compile
后面出现错误:package com.something does not exist ..我应该编辑哪些内容以使其正常工作?
确切错误:
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
您可以编辑您的问题向我们提供确切的错误? – Tom 2012-04-15 18:37:21
我已经添加了确切的错误。 – Pajushka 2012-04-15 18:53:25
你不能在一个普通的jar中轻松地包含外部库。你需要一些特殊的任务来完成这个任务。 – oers 2012-04-15 20:59:04