Skip to main content

Posts

Showing posts with the label Jar

Gradle : How To Exclude Files and Packages from a Jar file

How To Exclude File from a Jar file. Gradle task Jar has a property excludes which takes an array as an input and exclude these files from the Jar file it creates. Let's assume the following directory structure Following example excludes files from the Jar file. task createExcludingFiles(type :Jar){ from ('src'){ excludes = ["main/java/com/ekiras/demo/D.java","main/java/com/ekiras/demo/E.java"] } } This will exclude files D.java , E.java from the jar file. Run the gradle task using command gradle -q createExcludingFiles . The Jar file created will have the following files. META-INF/ META-INF/MANIFEST.MF main/ main/java/ main/java/com/ main/java/com/ekiras/ main/java/com/ekiras/demo/ main/java/com/ekiras/demo/A.java main/java/com/ekiras/demo/C.java main/java/com/ekiras/demo/F.java main/java/com/ekiras/demo/B.java main/java/com/ekiras/demo/p1/ main/java/com/ekiras/demo/p1/X.java main/java/com/ekiras/demo/p1/Z.java main/java/com/ekiras/de...

Gradle : How to create a Jar file

How to name a Jar file Lets take the following jar file for explaning the jar naming conventions. customName_wrapper_2.0.1_SNAPSHOT.jar A jar file has the following properties Property Description baseName customName appendix wrapper version 2.0.1 classifier SNAPSHOT archiveName - Here property archiveName if specified will override all the other naming conventions like baseName etc. It should be a fully qualified name of the Jar including the extension (.jar) Other Properties of Gradle Task :: Jar Property Description destinationDir Destination where jar is to be created manifest Include Manifest file from Directory from where files are to be read Creating a Jar file Let's assume the following directory structure Create a Jar file with all files. We can write a gradle task to include all files in src to our jar file as follows task createAll(type : Jar){ from 'src' } When we run the gradle task as gradle -q createAll will give the following files in the jar META-I...

Java : How to create a Jar with single or multiple files

How to create a jar file. We can make a jar file with a single class using the following commands Here can be replaced by the name of the jar file you want. 1. Create a jar file with single file jar --create --file=<FileName> <file-1> 2. Create a jar file with multiple files jar --create --file=<FileName> <file-1> <file-2> 3. Create a jar file with all files in a directory jar --create --file="<FileName> -C /path/to/dir/ ." Here -C specifies the directory and . specifies that it need to include all the files in te directory. Some of the shorthands for the above commands Option Shorthand --create -c --file -f --module-path -p --verbose -v --list -t --extract -x How to extract a jar file jar -xf <FileName> How to list the contents of a jar file jar -tf <FileName>