0

Could anyone would be so kind and explain how to make a single jar file with all maven dependencies in Netbeans Maven Java Application? In Eclipse user can Export to Runnable jar file and select Package required libraries into generated JAR, so all dependencies within project comes in created jar file. In Netbeans there is no such option. I have checked other answers, but the only thing i understand is that I have to add code to Build.xml file which is not even in the project.

Dainius Java
  • 125
  • 1
  • 4
  • 14

1 Answers1

2

The last time I had to do this I used the Maven Shade Plugin. It allows you to create a single JAR file and also handles dependency clashes.

A simpler solution (which doesn't handle dependency clashes) is to use the Maven Assembly Plugin.

Note that these are pure Maven solutions which should work in any IDE.

Adriaan Koster
  • 15,870
  • 5
  • 45
  • 60
  • Thans for answer. I have added maven-assembly-plugin to my POM like in [this](http://stackoverflow.com/questions/17654213/how-do-i-create-a-netbeans-style-jar-with-all-dependencies-in-a-lib-folder) link and I can run it from cmd. But now it gives me error for jasperreports.engine.JRRuntimeException. What a awful thing is Netbeans. – Dainius Java Jan 04 '16 at 12:22
  • With shade plugin i get error - no main manifest attribute. No luck with shade plugin :( – Dainius Java Jan 04 '16 at 12:39
  • @user2258338 It's not a Netbeans problem if your maven config isn't right. Have a look here [how to create an executable jar](http://maven.apache.org/plugins/maven-shade-plugin/examples/executable-jar.html). Further examples for the shade plugin you can find here [maven-shade-plugin examples](http://maven.apache.org/plugins/maven-shade-plugin/#Examples) – SubOptimal Jan 04 '16 at 15:33
  • @Suboptimal As I wrote before your comment - after creating jar file with shade plugin commander writes - no main manifest attribute. The same it wrote after I add code from your example to my POM and change main class to mine. I still can't get what is "main manifest attribute". What is it? – Dainius Java Jan 04 '16 at 18:27
  • I have combined POM shadow example with maven-assembly-plugin and jar became alive, BUT... no jasperreports or dynamicreports dependency added :( Just like in my first reply. And even if there is catch/exception joptionshow with error message joption shows with no message. F@#%. Thank for your answers folks. – Dainius Java Jan 04 '16 at 18:40