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
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
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

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Private Remote Maven Repository With Artipie
  • Creating Customized and Bootable Disk Images of Host Systems
  • Advantages of Python as an AI and ML Development Language
  • Three Best React Form Libraries

Trending

  • Why Angular and ASP.NET Core Make a Winning Team
  • Automate Your Quarkus Deployment Using Ansible
  • Edge Data Platforms, Real-Time Services, and Modern Data Trends
  • A Complete Guide to Open-Source LLMs

Generating an Executable JAR File From Project Containing Third Party Library

Yashwant Golecha user avatar by
Yashwant Golecha
·
Mar. 24, 14 · Interview
Like (1)
Save
Tweet
Share
19.61K 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
  • Creating Customized and Bootable Disk Images of Host Systems
  • Advantages of Python as an AI and ML Development Language
  • Three Best React Form Libraries

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • 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: