DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Private Remote Maven Repository With Artipie
  • While Performing Dependency Selection, I Avoid the Loss Of Sleep From Node.js Libraries' Dangers
  • Understanding ldd: The Linux Dynamic Dependency Explorer
  • Practical Use of Weak Symbols

Trending

  • Streamlining Event Data in Event-Driven Ansible
  • It’s Not About Control — It’s About Collaboration Between Architecture and Security
  • 5 Best Node.js Practices to Develop Scalable and Robust Applications
  • A Modern Stack for Building Scalable Systems

Generating an Executable JAR File From Project Containing Third Party Library

By 
Yashwant Golecha user avatar
Yashwant Golecha
·
Mar. 24, 14 · Interview
Likes (1)
Comment
Save
Tweet
Share
20.6K Views

Join the DZone community and get the full member experience.

Join For Free

a lot of times we write java utility programs which can be used as stand alone applications. we package them as executable jar file which could be shared with end users. if our code does not use any third party library, this process is kind of straight forward but when we have a third party library dependency, it gets a bit tricky. so in this post i will explain creation of jar file with inclusion of third party jar dependency . i am using jdeveloper ide for reference here but process would be more or less same on other ides like eclipse.

here are the steps to create an executable jar file

1. let’s assume you have written and tested your code. now right click on your project in jdeveloper and select deploy -> new deployment profile.

2. selct profile type as jar file. give a name to your deployment profile and click ok

create deployment profile

java : generating executable jar file from project containing third party library

3. on next screen, select compress archive and keep compression level as default.

4. check include manifest file (meta-inf/manifest.mf) this is the most important step as it will generate the manifest file which will make the jar file executable. select the main class whose main method should be called when jar is executed. (you can think this as starting point of your application)

include manifest file

include manifest file

5. expand file groups and check the filters. click ok. this will create a deployment profile.

deployment profile

deployment profile

6. once the deployment profile is created, right click on project, select deploy -> deploymentprofilename (name of profile created in previous steps)

deploymentprofilename

java : generating executable jar file from project containing third party library

7. click next, note down the path of deployed jar file.

 path of deployed jar file.

path of deployed jar file.

8. open the path mentioned in above steps and open that location. you will find your jar file which could be shared with other users.

so above steps are good enough when you don’t have a third party library dependency. now we will include third party library jar as part of our final jar only. you can either create a new deployment profile or edit the existing one.

1. right click project and select project properties -> deployment profiles -> profile to be edited

2. click edit

 click edit

java : generating executable jar file from project containing third party library

3. select file group and click new

select file group

select file group

4. give file group name and click ok

file group name

file group name

5. open contributors. remove existing entries

open contributors.

open contributors.

6. click add and browse for the jar file location on your file system

browse for the jar file location

browse for the jar file location

7. open filters tab

8. this is the most important step in case of third party libraries. uncheck manifest.mf when final jar is created if there are two manifest files, it would be a contradiction, so we need to remove the manifest of third party library in our jar.

uncheck manifest.mf

uncheck manifest.mf

9. click ok

10. redeploy your project. this time you will notice that resultant jar file is a bit larger in size than previous one as it will contain classes from third party library jar also.

that’s all you need to create an executable jar. go ahead and generate some utility jars which can be useful for everyone.

p.s. – command to run executable jar file java -jar filename.jar

Manifest file File system JAR (file format) Library Executable

Published at DZone with permission of Yashwant Golecha, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Private Remote Maven Repository With Artipie
  • While Performing Dependency Selection, I Avoid the Loss Of Sleep From Node.js Libraries' Dangers
  • Understanding ldd: The Linux Dynamic Dependency Explorer
  • Practical Use of Weak Symbols

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!