Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Single Jar with all project dependencies with maven

 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,

I want to create a single jar file of a complete project which include all dependencies within it.I have tried all the google answers but nothing workout for me.Could anyone please give some suggestion.
 
Saloon Keeper
Posts: 12128
258
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't do this without a custom class loader. This is not a limitation of Maven, but a limitation of Java.

You can try to use a tool such as One-Jar to bundle your jars together, but I'm not sure why you want a single jar in the first place. You can release your application as a zip file or with an installer, and you'll end up with a simple directory structure where your application can just reference the dependencies through the manifest file normally.
 
Ravi kapa
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply stephan, my intention for single jar is, once I execute jar using the java command from the command line then it should perform the required functionality.But the issue is my application contains dependencies(spring) which are not able to find by the JNI. Is there any way I can solve this issue?
 
Ravi kapa
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ravi kapa wrote:Thanks for the reply stephan, my intention for single jar is, once I execute jar using the java command from the command line then it should perform the required functionality.But the issue is my application contains dependencies(spring) which are not able to find by the JNI. Is there any way I can solve this issue? or how can it done by using installer?

 
Saloon Keeper
Posts: 22248
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a Maven mojo to create executable JAR files. It pulls in all the dependencies and adds a custom classloader to the jar to do what Stephan was talking about.

Try google for "maven executable jar".
 
Stephan van Hulst
Saloon Keeper
Posts: 12128
258
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's say you have a directory structure that looks like this:

my-app.jar should contain a manifest file that contains a class path entry that looks like this:

You can configure the maven-jar-plugin to do this for you by using the <addClasspath> and <classpathPrefix> elements under <archive>/<manifest>.

You can then distribute your application by zipping the whole thing.
 
Ravi kapa
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got the point.Thanks stephan and tim.
 
Sheriff
Posts: 7108
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that Maven's Shade plugin is the best for creating executable jars.
 
Sheriff
Posts: 21971
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
+1 for Shade.
 
I don't like that guy. The tiny ad agrees with me.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic