• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

maven create jar with dependencies (Eclipse plugin)

 
Zoltaan Szabo
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I wanted to export a project from Eclipse with the Maven plugin with The project has several dependencies, one from my workspace, and several fom e.g. Apache. The export took place, the .jar file was created. I added the main file entry to manifest.mf manually.
When i tried to run the jar, i got an error message:


How can i export a jar fle with the dependencies?
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to use the Assembly plugin to create a JAR file that includes all of the dependencies needed to run. In your assembly descriptor, mention 'jar' as a desired output format.
http://maven.apache.org/plugins/maven-assembly-plugin/index.html
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
378
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are looking for the assembly plugin. It exports the dependencies in addition to your jar. It doesn't place the dependencies inside the jar though. Instead it creates a file you can unzip that has all the dependencies.
 
Zoltaan Szabo
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. I checked out the plugin from the Apache repository, built it, put it to the Eclipse plugins folder, restarted Eclipse. Then i tried to Run as / Maven build... for my project with single goal. But i got an error:
I think it was a naive way what i have done.
Since then i have downloaded maven-assembly-plugin-2.4.jar, put it to the Eclipse plugins folder, restarted Eclipse, but it did not recognise the single goal.
What is the correct way to use (install?) this plugin?
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When using a mojo as a goal, you must supply the plugin name also. In other words:

mvn assembly:single

That way Maven knows that you want to run a mojo. If you don't specify a plugin, then Maven assumes you are referencing a build lifecycle phase, and there is no such phase as 'single'.

By the way, I usually include a lifecycle goal for the assembly plugin in the build section, usually associating it with the 'package' phase. They I can use "mvn package" to run the assembly plugin.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic