Java项目Ant构建错误

时间:2015-06-25 19:28:08

标签: java ant

您好我尝试使用ant打包我的项目。我对它的细节并不熟悉,并且在构建过程中遇到了麻烦。

我的项目目录结构如下所示:

project directory

当我运行ant脚本时,我收到以下错误:

 Buildfile: C:\Users\Trip Admin\Documents\Eclipse Projects\QuizServer\build.xml

 BUILD FAILED
 C:\Users\Trip Admin\Documents\Eclipse Projects\QuizServer\build.xml:12:      
 Cannot find C:\Users\Trip Admin\Documents\Eclipse Projects\QuizServer\nbproject\build-impl.xml 
 imported from C:\Users\Trip Admin\Documents\Eclipse Projects\QuizServer\build.xml

build.xml文件在开头包含以下行:

 <project name="QuizServer" default="default" basedir=".">
<description>Builds, tests, and runs the project QuizServer.</description>
<import file="nbproject/build-impl.xml"/>

warp.xml文件包含以下内容:

 <project name="quizserver" basedir="." default="main">

<property name="src.dir"     value="src"/>
<property name="build.dir"   value="build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir"     value="${build.dir}/jar"/>
<property name="main-class"  value="quizserver.QuizServer"/>
<property name="lib.dir"     value="libs"/>

<path id="classpath">
    <fileset dir="${lib.dir}" includes="**/*.jar"/>
</path>


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

<target name="compile">
    <mkdir dir="${classes.dir}"/>
    <javac srcdir="${src.dir}" includeantruntime = "false" source = "1.7" target = "1.7" fork="true" destdir="${classes.dir}" classpathref="classpath" compiler="classic" />
</target>

<target name="jar" depends="compile">
    <mkdir dir="${jar.dir}"/>
    <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
        <manifest>
            <attribute name="Main-Class" value="${main-class}"/>
        </manifest>
    </jar>
</target>

<target name="run" depends="jar">
    <java fork="true" classname="${main-class}">
        <classpath>
            <path refid="classpath"/>
            <path location="${jar.dir}/${ant.project.name}.jar"/>
        </classpath>
        <jvmarg value="-Xmx512m"/>
        <jvmarg value="-Xmx512m"/>
    </java>
</target>

<target name="clean-build" depends="clean,jar"/>

<target name="main" depends="clean,run"/>

我搜索无济于事,这显然是显而易见的,如果是这样,请你能指出问题可能是什么?

更新:我已将同一个名为NetBeans项目的build-impl.xml文件添加到该目录中。现在,当我运行build.xml文件时,我收到以下错误:

 Buildfile: C:\Users\Trip Admin\Documents\Eclipse Projects\QuizServer\build.xml
 -pre-init:
 -init-private:
 -init-user:
 -init-project:
 -init-macrodef-property:
 -do-init:
 -post-init:
 -init-check:

 BUILD FAILED
 C:\Users\Trip Admin\Documents\Eclipse Projects\QuizServer\build-impl.xml:226: Must set src.dir

Build-impl.xml文件行225和226如下:

 <target depends="-pre-init,-init-private,-init-user,-init-project,-do-init" name="-init-check">
    <fail unless="src.dir">Must set src.dir</fail>

非常感谢

2 个答案:

答案 0 :(得分:1)

错误很明显,Ant找不到这个文件:

nbproject/build-impl.xml

该文件夹不在您的目录结构中。

答案 1 :(得分:1)

此问题的解决方案是在NetBeans中。创建一个新的Netbeans项目并将其build-impl.xml文件复制到您的项目中。它应该工作