简体   繁体   中英

how to add source code to jar file using ant build.xml

I want to add all my source code to jar file using ant while creating jar file from source code.

I want to have two files 1- myProject.jar 2-myproject_source.jar

What should i use and where should i put it?

    <project name="myProject" >

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

<target name="compile">
    <mkdir dir="./build/classes"/>          
    <javac srcdir="./src" destdir="./build/classes"/>                   
</target>

<target name="jar">
    <mkdir dir="./build/jar"/>
    <jar destfile="./build/jar/DependencyFinder.jar" basedir="./build/classes">
        <manifest>
            <attribute name="DependencyFinder" value="main"/>
        </manifest>
    </jar>
</target>

</project>

Add this just before your <manifest> line:

<fileset dir="./src" includes="**/*.java"/>

You can add mulitple <fileset> statements if you want.

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