使用外部JAR构建Eclipse项目

时间:2017-05-09 19:59:13

标签: java jar ant build.xml

我的构建脚本如下:

<project default="main">
    <target name="main" depends="clear,compile,jar">
    </target>

    <target name="clear">
        <delete includeemptydirs="true">
            <fileset dir="../bin" includes="**/*" />
        </delete>
    </target>

    <target name="compile">
        <javac srcdir="../src" destdir="../bin" />
    </target>

    <target name="jar">
        <jar destfile="../jms.jar">
            <fileset dir="../bin">
                <include name="**/*.class" />
            </fileset>
            <zipgroupfileset dir="C:/Users/Jason/Project/apache-activemq-5.9" includes="activemq-5.9.jar" />
            <manifest>
                <section name="Information">
                    <attribute name="Version" value="1.1-02" />
                </section>
            </manifest>
        </jar>
    </target>
</project>

由于缺少JAR,我仍然因为无法编译我的类而遇到错误。我添加错误了吗?

C:\ Users \ Jason \ Project \ Workspace \ ActiveMQ \ src包含所有源文件 C:\ Users \ Jason \ Project \ apache-activemq-5.9是JAR文件的目标

以下是我的错误:

Buildfile: C:\Users\Jason\Project\Workspace\ActiveMQ\src\build.xml
clear:
compile:
    [javac] C:\Users\Jason\Project\Workspace\ActiveMQ\src\build.xml:12: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
    [javac] Compiling 2 source files to C:\Users\Jason\Project\Workspace\ActiveMQ\bin
    [javac] C:\Users\Jason\Project\Workspace\ActiveMQ\src\Publisher.java:1: error: package org.apache.activemq does not exist
    [javac] import org.apache.activemq.ActiveMQConnectionFactory;
    [javac]                           ^
    [javac] C:\Users\Jason\Project\Workspace\ActiveMQ\src\Publisher.java:2: error: package javax.jms does not exist
    [javac] import javax.jms.*;
    [javac] ^
    [javac] C:\Users\Jason\Project\Workspace\ActiveMQ\src\Publisher.java:7: error: cannot find symbol
    [javac]         ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
    [javac]         ^
    [javac]   symbol:   class ActiveMQConnectionFactory
    [javac]   location: class Publisher
    [javac] C:\Users\Jason\Project\Workspace\ActiveMQ\src\Publisher.java:7: error: cannot find symbol
    [javac]         ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
    [javac]                                                 ^
    [javac]   symbol:   class ActiveMQConnectionFactory
    [javac]   location: class Publisher
    [javac] 4 errors

1 个答案:

答案 0 :(得分:1)

您应该将类​​路径添加到javac目标,例如

<javac srcdir="../src" destdir="../bin" classpath="your-jar-file"/>

有关添加类路径的更多选项,请参阅Javac Task documentation