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)
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With