Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning 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
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

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

 
Sheriff
Posts: 3207
476
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus 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: 2702
130
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
Sheriff
Posts: 3207
476
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus 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
Sheriff
Posts: 3207
476
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus 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: 2702
130
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: 22022
108
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.
 
Can you smell this for me? I think this tiny ad smells like blueberry pie!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic