【发布时间】:2015-03-20 00:10:06
【问题描述】:
我想在我的 java 项目中包含外部 jar。我正在使用蚂蚁。外部 .jar 在文件夹 lib 中。我的 build.xml 看起来像这样:
<?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 后出现错误:包 com.something 不存在。我应该编辑什么才能使其正常工作?
确切的错误:
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
【问题讨论】:
-
您能否编辑您的问题以向我们提供确切的错误?
-
我已经添加了确切的错误。
-
您不能在普通的 jar 中轻松包含外部库。你需要像一个罐子这样的特殊任务来完成它。