• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
  • paul wheaton
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Rob Spoor
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:

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

 
Marshal
Posts: 4390
567
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2910
150
Google Web Toolkit Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 4390
567
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 4390
567
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2910
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22768
130
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Can you smell this for me? I think this tiny ad smells like blueberry pie!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic