1

我已经尝试并再次尝试为我的项目大纲开发一个 Ant Buildfile:

使用外部 jar 文件从 Windows 命令行运行 Java 时出现 NoClassDefFoundError

这是我尝试运行的构建文件:

<project>

    <target name="clean">
        <delete dir="build" />
    </target>

    <path id="jarpath">
        <fileset dir="C:\JAR">
            <include name="**" />
        </fileset>
    </path>

    <target name="compile">
        <mkdir dir="build/classes" />
        <javac srcdir="." destdir="build/classes" includeantruntime="false">
            <classpath id="jarpath" />
            <classpath>
                <pathelement path="jarpath" />
            </classpath>
        </javac>
    </target>

    <target name="jar">
        <mkdir dir="build/jar" />
        <jar destfile="build/jar/TestCase1.jar" basedir="build/classes">
            <manifest>
                <attribute name="Main-Class" value="NSSR.TestCase1" />
            </manifest>
        </jar>
        <jar destfile="build/jar/UniversalVariables.jar" basedir="build/classes">
            <manifest>
                <attribute name="Main-Class" value="NSSR.UniversalVariables" />
            </manifest>
        </jar>
    </target>

</project>

当我将“ant compile”放入 Windows 的命令行时,它给了我一个巨大的错误:

Buildfile: C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Case
s\src\build.xml

compile:
    [javac] Compiling 4 source files to C:\Documents and Settings\jradcliffe\wor
kspace\ITSM_Upgrade_Test_Cases\src\build\classes
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\NSSR\TestCase1.java:3: package com.thoughtworks.selenium does not exist
    [javac] import com.thoughtworks.selenium.*;
    [javac] ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\NSSR\TestCase1.java:4: package org.junit does not exist
    [javac] import org.junit.After;
    [javac]                 ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\NSSR\TestCase1.java:5: package org.junit does not exist
    [javac] import org.junit.Before;
    [javac]                 ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\NSSR\TestCase1.java:6: package org.junit does not exist
    [javac] import org.junit.Test;
    [javac]                 ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\NSSR\TestCase1.java:10: cannot find symbol
    [javac] symbol: class SeleneseTestCase
    [javac] public class TestCase1 extends SeleneseTestCase {
    [javac]                                ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\TestCase1.java:3: package com.thoughtworks.selenium does not exist
    [javac] import com.thoughtworks.selenium.*;
    [javac] ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\TestCase1.java:4: package org.junit does not exist
    [javac] import org.junit.After;
    [javac]                 ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\TestCase1.java:5: package org.junit does not exist
    [javac] import org.junit.Before;
    [javac]                 ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\TestCase1.java:6: package org.junit does not exist
    [javac] import org.junit.Test;
    [javac]                 ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\TestCase1.java:10: cannot find symbol
    [javac] symbol: class SeleneseTestCase
    [javac] public class TestCase1 extends SeleneseTestCase {
    [javac]                                ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\NSSR\TestCase1.java:23: cannot find symbol
    [javac] symbol  : class Before
    [javac] location: class NSSR.TestCase1
    [javac]     @Before
    [javac]      ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\NSSR\TestCase1.java:30: cannot find symbol
    [javac] symbol  : class Test
    [javac] location: class NSSR.TestCase1
    [javac]     @Test
    [javac]      ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\NSSR\TestCase1.java:65: cannot find symbol
    [javac] symbol  : class After
    [javac] location: class NSSR.TestCase1
    [javac]     @After
    [javac]      ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\TestCase1.java:23: cannot find symbol
    [javac] symbol  : class Before
    [javac] location: class TestCase1
    [javac]     @Before
    [javac]      ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\TestCase1.java:30: cannot find symbol
    [javac] symbol  : class Test
    [javac] location: class TestCase1
    [javac]     @Test
    [javac]      ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\TestCase1.java:65: cannot find symbol
    [javac] symbol  : class After
    [javac] location: class TestCase1
    [javac]     @After
    [javac]      ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\NSSR\TestCase1.java:25: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class NSSR.TestCase1
    [javac]             selenium = new DefaultSelenium("localhost", 4444, "*fire
fox",
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\NSSR\TestCase1.java:25: cannot find symbol
    [javac] symbol  : class DefaultSelenium
    [javac] location: class NSSR.TestCase1
    [javac]             selenium = new DefaultSelenium("localhost", 4444, "*fire
fox",
    [javac]                            ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\NSSR\TestCase1.java:27: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class NSSR.TestCase1
    [javac]             selenium.start();
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\NSSR\TestCase1.java:32: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class NSSR.TestCase1
    [javac]             selenium.open(UniversalVariables.loginPage);
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\NSSR\TestCase1.java:33: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class NSSR.TestCase1
    [javac]             selenium.type("name=USERNAME", UniversalVariables.userna
me);
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\NSSR\TestCase1.java:34: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class NSSR.TestCase1
    [javac]             selenium.type("name=PASSWORD", UniversalVariables.passwo
rd);
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\NSSR\TestCase1.java:35: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class NSSR.TestCase1
    [javac]             selenium.click("link=Submit");
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\NSSR\TestCase1.java:36: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class NSSR.TestCase1
    [javac]             selenium.waitForPageToLoad("60000");
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\NSSR\TestCase1.java:37: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class NSSR.TestCase1
    [javac]             selenium.open("/itg/dashboard/app/portal/PageView.jsp?IS
_WINDOID=N");
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\NSSR\TestCase1.java:38: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class NSSR.TestCase1
    [javac]             selenium.click("link=Create");
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\NSSR\TestCase1.java:39: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class NSSR.TestCase1
    [javac]             selenium.click("link=Request");
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\NSSR\TestCase1.java:40: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class NSSR.TestCase1
    [javac]             selenium.waitForPageToLoad("30000");
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\NSSR\TestCase1.java:41: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class NSSR.TestCase1
    [javac]             selenium.select("name=REQUEST_TYPE_CREATE",
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\NSSR\TestCase1.java:43: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class NSSR.TestCase1
    [javac]             selenium.click("css=span.secBtn > a");
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\NSSR\TestCase1.java:44: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class NSSR.TestCase1
    [javac]             selenium.waitForPageToLoad("30000");
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\NSSR\TestCase1.java:55: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class NSSR.TestCase1
    [javac]             selenium.type("id=REQ.DESCRIPTION", title);
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\NSSR\TestCase1.java:56: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class NSSR.TestCase1
    [javac]             selenium.type("id=REQ.P.REQUESTORAC_TF", req);
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\NSSR\TestCase1.java:57: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class NSSR.TestCase1
    [javac]             selenium.select("id=REQ.P.REQUESTOR_DEPT", dept);
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\NSSR\TestCase1.java:58: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class NSSR.TestCase1
    [javac]             selenium.type("id=REQ.P.DETAIL_DESC", desc);
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\NSSR\TestCase1.java:59: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class NSSR.TestCase1
    [javac]             selenium.type("REQ.P.REQ_COMPL_DATE", date);
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\NSSR\TestCase1.java:60: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class NSSR.TestCase1
    [javac]             selenium.click("link=Submit");
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\NSSR\TestCase1.java:61: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class NSSR.TestCase1
    [javac]             selenium.waitForPageToLoad("30000");
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\NSSR\TestCase1.java:62: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class NSSR.TestCase1
    [javac]             selenium.refresh();
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\NSSR\TestCase1.java:67: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class NSSR.TestCase1
    [javac]             selenium.stop();
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\TestCase1.java:25: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class TestCase1
    [javac]             selenium = new DefaultSelenium("localhost", 4444, "*fire
fox",
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\TestCase1.java:25: cannot find symbol
    [javac] symbol  : class DefaultSelenium
    [javac] location: class TestCase1
    [javac]             selenium = new DefaultSelenium("localhost", 4444, "*fire
fox",
    [javac]                            ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\TestCase1.java:27: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class TestCase1
    [javac]             selenium.start();
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\TestCase1.java:32: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class TestCase1
    [javac]             selenium.open(UniversalVariables.loginPage);
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\TestCase1.java:33: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class TestCase1
    [javac]             selenium.type("name=USERNAME", UniversalVariables.userna
me);
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\TestCase1.java:34: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class TestCase1
    [javac]             selenium.type("name=PASSWORD", UniversalVariables.passwo
rd);
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\TestCase1.java:35: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class TestCase1
    [javac]             selenium.click("link=Submit");
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\TestCase1.java:36: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class TestCase1
    [javac]             selenium.waitForPageToLoad("60000");
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\TestCase1.java:37: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class TestCase1
    [javac]             selenium.open("/itg/dashboard/app/portal/PageView.jsp?IS
_WINDOID=N");
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\TestCase1.java:38: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class TestCase1
    [javac]             selenium.click("link=Create");
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\TestCase1.java:39: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class TestCase1
    [javac]             selenium.click("link=Request");
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\TestCase1.java:40: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class TestCase1
    [javac]             selenium.waitForPageToLoad("30000");
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\TestCase1.java:41: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class TestCase1
    [javac]             selenium.select("name=REQUEST_TYPE_CREATE",
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\TestCase1.java:43: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class TestCase1
    [javac]             selenium.click("css=span.secBtn > a");
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\TestCase1.java:44: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class TestCase1
    [javac]             selenium.waitForPageToLoad("30000");
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\TestCase1.java:55: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class TestCase1
    [javac]             selenium.type("id=REQ.DESCRIPTION", title);
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\TestCase1.java:56: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class TestCase1
    [javac]             selenium.type("id=REQ.P.REQUESTORAC_TF", req);
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\TestCase1.java:57: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class TestCase1
    [javac]             selenium.select("id=REQ.P.REQUESTOR_DEPT", dept);
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\TestCase1.java:58: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class TestCase1
    [javac]             selenium.type("id=REQ.P.DETAIL_DESC", desc);
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\TestCase1.java:59: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class TestCase1
    [javac]             selenium.type("REQ.P.REQ_COMPL_DATE", date);
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\TestCase1.java:60: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class TestCase1
    [javac]             selenium.click("link=Submit");
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\TestCase1.java:61: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class TestCase1
    [javac]             selenium.waitForPageToLoad("30000");
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\TestCase1.java:62: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class TestCase1
    [javac]             selenium.refresh();
    [javac]             ^
    [javac] C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cas
es\src\TestCase1.java:67: cannot find symbol
    [javac] symbol  : variable selenium
    [javac] location: class TestCase1
    [javac]             selenium.stop();
    [javac]             ^
    [javac] 64 errors

BUILD FAILED
C:\Documents and Settings\jradcliffe\workspace\ITSM_Upgrade_Test_Cases\src\build
.xml:15: Compile failed; see the compiler error output for details.

Total time: 1 second

基本上,它似乎无法识别我的 jar 文件中的任何内容,我认为这是有道理的,因为我没有在编译目标中引用它们。问题是我不知道如何引用它们(这是我除了 Hello World 之外的第一个 Buildfile)。

谢谢

4

3 回答 3

1

您遇到的问题是设置和管理类路径。这是迄今为止 ANT 构建中最常见的问题......

当我查看您的代码时,您似乎应该运行 junit...

我整理了一个修改后的构建文件,演示了以下内容:

  1. 使用apache ivy管理所有 3rd 方 jar 依赖项
  2. 使用 ant junit 任务运行 junit 测试
  3. 使用类路径打包一个完整的可执行 jar

希望能帮助到你。

例子

该项目是根据以下问题中提供的源代码构建的:

使用外部 jar 文件从 Windows 命令行运行 Java 时出现 NoClassDefFoundError

|-- build.xml
`-- src
    `-- NSSR
        |-- TestCase1.java
        `-- UniversalVariables.java

您需要运行以下目标一次才能安装ivy 插件

ant bootstrap

然后按如下方式运行构建

ant clean jar

然后可以按如下方式执行生成的jar;

java -jar build/dist/demo.jar

构建.xml

<project name="demo" default="jar" xmlns:ivy="antlib:org.apache.ivy.ant">

    <!--
    ==========
    Properties
    ==========
    -->
    <property name="src.dir"     location="src"/>
    <property name="build.dir"   location="build"/>
    <property name="classes.dir" location="${build.dir}/classes"/>
    <property name="dist.dir"    location="${build.dir}/dist"/>

    <property name="jar.file"       location="${dist.dir}/${ant.project.name}.jar"/>
    <property name="jar.main.class" value="NSSR.TestCase1"/>

    <property name="javac.deprecation" value="false"/>
    <property name="junit.haltonfailure" value="false"/>

    <!--
    =======
    Targets
    =======
    -->
    <target name="bootstrap" description="Install ivy">
        <mkdir dir="${user.home}/.ant/lib"/>
        <get src="https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&amp;g=org.apache.ivy&amp;a=ivy&amp;v=LATEST&amp;e=jar"
             dest="${user.home}/.ant/lib/ivy.jar"/>
    </target>

    <target name="init" description="Resolve dependencies and set classpaths">
        <ivy:cachepath pathid="build.path" conf="default">
            <dependency org="org.seleniumhq.selenium" name="selenium" rev="2.0rc2"/>
            <dependency org="junit" name="junit" rev="4.10"/>
        </ivy:cachepath>
    </target>

    <target name="compile" depends="init" description="Compile the code">
        <mkdir dir="${classes.dir}" />
        <javac srcdir="." destdir="${classes.dir}" includeantruntime="false" deprecation="${javac.deprecation}" classpathref="build.path"/>
    </target>

    <target name="test" depends="compile" description="Run unit tests">
        <mkdir dir="${build.dir}/tests"/>

        <junit printsummary="yes" haltonfailure="${junit.haltonfailure}">
            <classpath>
                <path refid="build.path"/>
                <pathelement path="${classes.dir}"/>
            </classpath>
            <formatter type="plain"/>
            <batchtest fork="yes" todir="${build.dir}/tests">
                <fileset dir="${src.dir}" includes="**/*Test*.java"/>
            </batchtest>
        </junit>
    </target>

    <target name="jar" depends="test" description="Build jar files">
        <ivy:retrieve pattern="${dist.dir}/lib/[artifact]-[revision](-[classifier]).[ext]"/>

        <manifestclasspath property="jar.classpath" jarfile="${jar.file}">
            <classpath>
                <fileset dir="${dist.dir}/lib" includes="*.jar"/>
            </classpath>
        </manifestclasspath>

        <jar destfile="${jar.file}" basedir="${classes.dir}">
            <manifest>
                <attribute name="Main-Class" value="${jar.main.class}" />
                <attribute name="Class-Path" value="${jar.classpath}" />
            </manifest>
        </jar>
    </target>

    <target name="clean" description="Remove build files">
        <delete dir="${build.dir}" />
    </target>

    <target name="clean-all" depends="clean" description="Additionally purge ivy cache">
        <ivy:cleancache/>
    </target>

</project>
于 2012-07-09T21:09:48.853 回答
0

Try this:

 <classpath>
      <pathelement path="${classpath}"/>
      <fileset dir="lib">
        <include name="**/*.jar"/>
      </fileset>
      <pathelement location="classes"/>
      <dirset dir="${build.dir}">
        <include name="apps/**/classes"/>
        <exclude name="apps/**/*Test*"/>
      </dirset>
      <filelist refid="third-party_jars"/>
    </classpath>

See Writing a simple build file

于 2012-07-09T16:10:57.737 回答
0

尝试更改您的compile目标,以便在<javac>使用<classpath>范围内refid而不是id如下所示:

<target name="compile">
    <mkdir dir="build/classes" />
    <javac srcdir="." destdir="build/classes" includeantruntime="false">
        <classpath refid="jarpath" />
    </javac>
</target>
于 2012-07-10T06:30:47.053 回答