Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

generate jars with source code using Ant

Tags:

jar

ant

I use ant for creating .jar files in Eclipse.

I need to generate jar for my project which also contains source code along with the class file. How do we do it?

Another question: what is a debug jar and how to create it using ant? (have heard about it somewhere and trying to relate them both)

like image 230
Anand Avatar asked Feb 21 '11 08:02

Anand


People also ask

How do I make an Ant project jar?

jar an executable jar file, we need to add the manifest with the Main-Class meta attribute. To execute the jar task, wrap it inside a target, most commonly, the build or package target, and execute them. Running Ant on this file creates the util. jar file for us.

Does jar file contain source code?

A jar is analogous to a zip file, so they may or may not contain the source code you need for development. You can read about jar files here.


1 Answers

I would modify your jar task to include multiple filesets; one for the classes and one for the source files.

<jar destfile="${target.dir}/my-app.jar">     <fileset dir="${target.dir}/classes" />     <fileset dir="${src.dir}" includes="**/*.java"/> </jar> 

Packaging should be treated as a separate concern from compiling. This will give you more flexibility. For example, you may want to add other filesets to the jar (e.g. properties files), or you may want to package your sources in a jar file that is separate from your class files.

like image 103
KevinS Avatar answered Sep 27 '22 00:09

KevinS