Tutorials Navigation
Apache Ant Tutorial - Creating JAR files
Tutorial Name: Apache Ant Tutorial - Creating JAR files
Category: PC Tutorials
Submitted By: hoot
Date Added:
Comments: 2
Views: 732
Related Forum: PC Building Forum
Share:
The next logical step after compiling your java source files, is to build the java archive, i.e., the JAR file. Creating JAR files with Ant is quite easy with the jar task. The commonly used attributes of the jar task are as follows
Sr.No.1-basedir
The base directory for the output JAR file. By default, this is set to the base directory of the project.
Sr.No.2-compress
Advises Ant to compress the file as it creates the JAR file.
Sr.No.3-keepcompression
While the compress attribute is applicable to the individual files, the keepcompression attribute does the same thing, but it applies to the entire archive.
Sr.No.4-destfile
The name of the output JAR file.
Sr.No.5-duplicate
Advises Ant on what to do when duplicate files are found. You could add, preserve, or fail the duplicate files.
Sr.No.6-excludes
Advises Ant to not include these comma separated list of files in the package.
Sr.No.7-excludesfile
Same as above, except the exclude files are specified using a pattern.
Sr.No.8-inlcudes
Inverse of excludes.
Sr.No.9-includesfile
Inverse of excludesfile.
Sr.No.10-update
Advises Ant to overwrite files in the already built JAR file.
Continuing our Hello World Fax Application project, let us add a new target to produce the jar files. But before that, let us consider the jar task given below.
<jar destfile = "${web.dir}/lib/util.jar"
basedir = "${build.dir}/classes"
includes = "faxapp/util/**"
excludes = "**/Test.class" />
Here, the web.dir property points to the path of the web source files. In our case, this is where the util.jar will be placed.
The build.dir property in this example points to the build folder where the class files for the util.jar can be found.
In this example, we create a jar file called util.jar using the classes from the faxapp.util.* package. However, we are excluding the classes that end with the name Test. The output jar file will be placed in the web application lib folder.
If we want to make the util.jar an executable jar file we need to add the manifest with the Main-Class meta attribute.
Therefore, the above example will be updated as
<jar destfile = "${web.dir}/lib/util.jar"
basedir = "${build.dir}/classes"
includes = "faxapp/util/**"
excludes = "**/Test.class">
<manifest>
<attribute name = "Main-Class" value = "com.tutorialspoint.util.FaxUtil"/>
</manifest>
</jar>
To execute the jar task, wrap it inside a target, most commonly, the build or package target, and execute them.
target name = "build-jar">
<jar destfile = "${web.dir}/lib/util.jar"
basedir = "${build.dir}/classes"
includes = "faxapp/util/**"
excludes = "**/Test.class">
<manifest>
<attribute name = "Main-Class" value = "com.tutorialspoint.util.FaxUtil"/>
</manifest>
</jar>
</target>
Running Ant on this file creates the util.jar file for us.
The following outcome is the result of running the Ant file
C:\>ant build-jar
Buildfile: C:\build.xml
BUILD SUCCESSFUL
Total time: 1.3 seconds
The util.jar file is now placed in the output folder.
Ratings
Comments
Related Tutorials
- 01. Emulating Xbox 360 on PC for Running COD4 With Mods(3,526)
- 02. How to: Matrix Numbers | Batch File(1,913)
- 03. How to Password Protect Files on Windows(859)
- 04. How to play Socom 2/3/ and Combined Assault on PC(6,746)
- 05. Modern Warfare 2 Vac Ban Bypass Tutorial(6,169)
- 06. How to embed an image on TheTechGame(3,104)
- 07. [PC] NIOH 2 OTHER USER SAVE RESIGN(13,017)
- 08. Host bot lobbies! Full Tutorial!(11,356)
- 09. Unban yourself [Plutonium BO2](14,262)
- 10. Fall Guys - How to Change Your Name Color on Fall Guys(8,396)
- 11. Best Crosshair Settings for Valorant(6,534)
- 12. Othercide The Surgeon Boss Guide(2,548)
- 13. Othercide Remembrances Unlock Guide(4,476)
- 14. Othercide Beginners Tips and Tricks(2,719)
- 15. How to Fix Grounded Crashes, Loading Time, Low FPS and Other(4,855)
"Apache Ant Tutorial - Creating JAR files" :: Login/Create an Account :: 2 comments