由于非加载依赖的Task类导致Ant构建失败

时间:2010-12-24 19:06:47

标签: java eclipse ant

Buildfile: /.../build.xml
build:
buildtests:
tests:

BUILD FAILED
/.../build.xml:43: Problem: failed to create task or type junit
Cause: Could not load a dependent class org/apache/tools/ant/Task
   It is not enough to have Ant's optional JARs
   you need the JAR files that the optional tasks depend upon.
   Ant's optional task dependencies are listed in the manual.
Action: Determine what extra JAR files are needed, and place them in one of:
    -/Applications/eclipse/plugins/org.apache.ant_1.7.1.v20090120-1145/lib
    -/Users/cjwalsh/.ant/lib
    -a directory added on the command line with the -lib argument

Do not panic, this is a common problem.
The commonest cause is a missing JAR.

This is not a bug; it is a configuration problem


Total time: 512 milliseconds

...我已经检查了所有推荐的目录,但我仍然继续使这个构建失败。我调查过的具体JAR'ant.jar'有'Task'类,它位于'/Applications/eclipse/plugins/org.apache.ant_1.7.1.v20090120-1145/lib'中目录。我是否还需要手动将此类路径添加到我的build.xml中?这是我的build.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project name="springapp" basedir="." default="build">
<property file="build.properties"></property>

<property name="src.dir" value="src"></property>
<property name="web.dir" value="war"></property>
<property name="build.dir" value="${web.dir}/WEB-INF/classes"></property>
<property name="name" value="springapp"></property>
<property name="test.dir" value="test"></property>

<path id="master-classpath">
    <fileset dir="${web.dir}/WEB-INF/lib">
        <include name="*.jar" />
    </fileset>
    <fileset dir="${appserver.lib}">
        <include name="servlet*.jar"></include>
    </fileset>
    <pathelement path="${build.dir}"></pathelement>
</path>

<target name="build" description="Compile main source tree java files">
    <mkdir dir="${build.dir}" />
    <javac destdir="${build.dir}" source="1.5" target="1.5" debug="true" deprecation="false" optimize="false"
        failonerror="true">

        <src path="${src.dir}" />
        <classpath refid="master-classpath" />  
    </javac>
</target>

<target name="buildtests" description="Compile test tree java files">
    <mkdir dir="${build.dir}" />
    <javac destdir="${build.dir}" source="1.5" target="1.5" debug="true"
        deprecation="false" optimize="false" failonerror="true">

        <src path="${test.dir}"></src>
        <classpath refid="master-classpath"></classpath>
    </javac>
</target>

<target name="tests" depends="build, buildtests" description="Run tests">
    <junit printsummary="on" fork="false" haltonfailure="false" failureproperty="tests.failed"
        showoutput="true">

        <classpath refid="master-classpath"></classpath>

        <formatter type="brief" usefile="false" />

        <batchtest>
            <fileset dir="${build.dir}">
                <include name="**/*Tests.*" />
            </fileset>
        </batchtest>
    </junit>

    <fail if="tests.failed">
        tests.failed=${tests.failed}
        ***********************************************************************
        ***********************************************************************
        ****    One or more tests failed! Check the output ...  *************** 
        ***********************************************************************
        ***********************************************************************
    </fail>
</target>

<target name="deploy" depends="build" description="Deploy the application">
    <copy todir="${deploy.path}/${name}" preservelastmodified="true">
        <fileset dir="${web.dir}">
            <include name="**/*.*" />
        </fileset>
    </copy>
</target>

<target name="deploywar" depends="build" description="Deploy application as WAR file">
    <war destfile="${name}.war" webxml="${web.dir}/WEB-INF/web.xml">
        <fileset dir="${web.dir}">
            <include name="**/*.*"></include>
        </fileset>
    </war>
    <copy todir="${deploy.path}" preservelastmodified="true">
        <fileset dir=".">
            <include name="*.war"></include>
        </fileset>
    </copy>
</target>

<path id="catalina-ant-classpath">
    <fileset dir="${appserver.lib}">
        <include name="catalina-ant.jar"></include>
    </fileset>
</path>

<taskdef name="install" classname="org.apache.catalina.ant.InstallTask">
    <classpath refid="catalina-ant-classpath"></classpath>
</taskdef>

<taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask">
    <classpath refid="catalina-ant-classpath"></classpath>
</taskdef>

<taskdef name="list" classname="org.apache.catalina.ant.ListTask">
    <classpath refid="catalina-ant-classpath" />
</taskdef>

<taskdef name="start" classname="org.apache.catalina.ant.StartTask">
    <classpath refid="catalina-ant-classpath"></classpath>
</taskdef>

<taskdef name="stop" classname="org.apache.catalina.ant.StopTask">
    <classpath refid="catalina-ant-classpath"></classpath>
</taskdef>

<target name="install" description="Install application in Tomcat">
    <install url="${tomcat.manager.url}" username="${tomcat.manager.username}"
        password="${tomcat.manager.password}"
        path="/${name}"
        war="${name}" />
</target>

<target name="reload" description="Reload applicatio in Tomcat">
    <reload url="${tomcat.manager.url}" username="${tomcat.manager.username}"
        password="${tomcat.manager.password}"
        path="/${name}" />
</target>

<target name="start" description="Start tomcat application">
    <start url="${tomcat.manager.url}" username="${tomcat.manager.username}"
        password="${tomcat.manager.password}"
        path="/${name}" />
</target>

<target name="stop" description="Stop Tomcat application">
    <stop url="${tomcat.manager.url}"
             username="${tomcat.manager.username}"
             password="${tomcat.manager.password}"
             path="/${name}" />
</target>

<target name="list" description="List Tomcat applications">
    <list url="${tomcat.manager.url}"
             username="${tomcat.manager.username}"
             password="${tomcat.manager.password}" />
</target>
</project>

1 个答案:

答案 0 :(得分:1)

你是从Eclipse中开始蚂蚁的吗?

请检查菜单{运行|外部工具配置...} Classpath选项卡包含“Ant Home”。扩展后,是否指向有效文件?