Tuesday, December 30, 2014

Building a executable JAR file with external libraries through JDeveloper

Building a executable JAR file with external libraries through JDeveloper

This post explain the different approaches to build the executable JAR file with external libraries through JDeveloper.

Referring the external libraries from JAR:

Right Click project and select properties
Click on Deployment and create new JAR deployment profile.
Select "Include Manifest File" option.
Select the main class.



Create a manifest file(any location) and add the required jar files to the Class-Path header

Class-Path.mf

Class-Path: json.jar log4j.jar

 End the Class-Path.mf file by a carriage return.


Add the Class-Path.mf file to Additional Manifest Files to Merge into Manifest.mf



Then right click on project select the profile created under deploy. Select Deploy to JAR File.
Click finish.

META-INF\MAIFEST.MF file in the generated file will have the Main-Class and Class-Path headers defined.

Executing the jar:

Place the dependent jars to the same folder where the jar file generated in the previous step exists.



java -jar TokenizerService.jar

Including the content of external libraries to JAR:

Right Click project and select properties
Click on Deployment and create new JAR deployment profile.
Select "Include Manifest File" option.
Select the main class.
Create New File Group of type Dependency Analysis


Select the Contributors under new file group you have created
Select the Libraries Tab.
Select the required libraries  and select the default option "Include Contents in Output".


Then right click on project select the profile created under deploy. Select Deploy to JAR File.
Click finish.
The content of the json.jar file will be included into the generated jar.

Executing the jar:

java -jar TokenizerService.jar


No comments:

Post a Comment