
If we want to make the util.jar an executable jar file, we need to add the manifest with the Main-Class meta attribute. The output jar file will be placed in the web application lib folder. However, we are excluding the classes that end with the name Test. In this example, we create a jar file called util.jar using the classes from the faxapp.util.* package. The build.dir property in this example, points to the build folder, where the class files for the util.jar can be found. In our case, this is where the util.jar will be placed. Here, the web.dir property points to the path of the web source files. Same as above, except the exclude files are specified using a pattern.Īdvises Ant to overwrite files in the already built JAR file.Ĭontinuing our Hello World Fax Application project, let us add a new target to produce the jar files.īut before that, let us consider the jar task given below. You could add, preserve, or fail the duplicate files.Īdvises Ant to not include these comma separated list of files in the package. While the compress attribute is applicable to the individual files, the keepcompression attribute does the same thing, but it applies to the entire archive.Īdvises Ant on what to do when duplicate files are found.

By default, this is set to the base directory of the project.Īdvises Ant to compress the file as it creates the JAR file. The base directory for the output JAR file.

The commonly used attributes of the jar task are as follows − Sr.No Creating JAR files with Ant is quite easy with the jar task.
Compile java jar file how to#
Compile java jar file portable#
A jar file is a portable container of classes.
Compile java jar file zip#
The classes in a jar file are stored in a compressed format, much like a zip file.

How to Create a Jar File in Java See Java: Tips and Tricks for similar articles.Ī Java class can be stored in a jar (Java Archive) file.
