加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – Ant包含外部.jar

发布时间:2020-12-15 00:36:45 所属栏目:Java 来源:网络整理
导读:我想在我的 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
我想在我的 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后出现错误:package 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

解决方法

你应该尝试没有包含属性:
<fileset dir="lib" />

在jar部分中,您包含以下类:

<zipgroupfileset includes="*.jar" dir="lib"/>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读