This week's book giveaways are in the Cloud and AI/ML forums.
We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Maven: Create Runnable Jar with Dependency Jar Files (Fat Jar)

 
Saloon Keeper
Posts: 2650
333
Android Eclipse IDE Angular Framework MySQL Database TypeScript Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my first attempting at building with Maven (previously I have always used Ant).

I am trying to assemble a runnable jar file which includes the dependent jar files for netty, kafka, etc.  I am able to build without any errors, but when I try and run by jar, I find that the jars for the dependencies were not bundled in the jar which was built.  

Any hints to help me sort this out?  I'm sure hoping that it is something simple.

My pom.xml:
Console output from build:
 
Bartender
Posts: 2323
100
Google Web Toolkit Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not much sure about this since I haven't done it, but I think this might help : https://www.mkyong.com/maven/create-a-fat-jar-file-maven-assembly-plugin/
Most of my maven builds are thin jars with dependencies deployed separately and not a far jar as your problem is stated.
 
Ron McLeod
Saloon Keeper
Posts: 2650
333
Android Eclipse IDE Angular Framework MySQL Database TypeScript Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Following the advice from this StackOverflow thread and this other StackOverflow thread, I was able to create the runnable fat jar I wanted using the Apache Maven Assembly Plugin


 
Ron McLeod
Saloon Keeper
Posts: 2650
333
Android Eclipse IDE Angular Framework MySQL Database TypeScript Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

salvin francis wrote:I am not much sure about this since I haven't done it, but I think this might help : https://www.mkyong.com/maven/create-a-fat-jar-file-maven-assembly-plugin/

Thanks for the link It looks like ti is also using the assembly plug-in.
 
salvin francis
Bartender
Posts: 2323
100
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Happy to help . The reason why you found it difficult was that it is not a common scenario to build a fat jar in maven. Even if you want to run it as a standalone jar, maybe you can consider including dependencies in classpath instead of bundling them ?
 
Sheriff
Posts: 21773
103
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I prefer the shade plugin over the assembly plugin for fat JARs. I've also used the One Jar maven plugin but that creates a fat JAR with the dependencies included as JAR files with a custom class loader.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!