简体   繁体   中英

Ant Build - src does not exist

i'm creating a build.xml file that will create a jar file ,this jar file should run the main class i set in the manifest.. here is the code,

<description>
    Create a Java Project (JAR) with Ant build script
</description>

<target name="init" description="Initializes properties">
    <echo message="initializing properties..." />
    <property name="src.dir" location="src" />
    <property name="build.dir" location="build" />
    <property name="project.name" value="TestMain" />
    <property name="build.dir" value="build" />
    <property name="classes.dir" value="${build.dir}/classes" />
</target>
<presetdef name="javac">
    <javac includeantruntime="false" />
</presetdef>

<target name="clean" description="delete the build directory" depends="init">
    <echo message="deleting temporary directory..." />
    <delete dir="${build.dir}" />
    <delete file="${project.name}.jar"/>
</target>

<target name="prepare" description="Creates the build and classes directories" depends="clean">
    <echo message="creating temporary directory..." />
    <mkdir dir="${classes.dir}" />
</target>

<target name="compile" description="Compiles the code" depends="prepare">
    <echo message="compiling codes..." />
    <javac srcdir="${src.dir}" destdir="${classes.dir}" />
</target>


<target name="jarfile" description="JARs the code" depends="compile">
    <echo message="creating jar file..." />
    <jar destfile="${project.name}.jar" basedir="${classes.dir}" includes="com/**"> 
        <manifest>
            <attribute name="Main-Class" value="com.java.apache.ant.TestMain" />
        </manifest>
    </jar>
</target>

I got an error in target:compile , it says src does not exist

Buildfile: C:\_GIT\ApacheAnt\deploy\build.xml
Trying to override old definition of task javac
init:
     [echo] initializing properties...
clean:
     [echo] deleting temporary directory...
   [delete] Deleting directory C:\_GIT\ApacheAnt\deploy\build
prepare:
     [echo] creating temporary directory...
    [mkdir] Created dir: C:\_GIT\ApacheAnt\deploy\build\classes
compile:
     [echo] compiling codes...

BUILD FAILED
C:\_GIT\ApacheAnt\deploy\build.xml:33: srcdir "C:\_GIT\ApacheAnt\deploy\src" does not exist!

here is the structure of my project

src
 |__com.... *.java

build
 |__com...*.class

deploy
 |__build.xml

As i checked the build/classes folder that was created inside the deploy folder no *.class file was copied.. any problem with my xml file? thanks

Looks, your build xml considering "deploy" as base directory for project which resulting in to the "src" as "deploy/src". Please check your "basedir" attribute in "project" tag to set it properly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM