Meaningless Drivel is fun!*
The moose likes Ant, Maven and Other Build Tools and the fly likes maven create jar with dependencies (Eclipse plugin) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "maven create jar with dependencies (Eclipse plugin)" Watch "maven create jar with dependencies (Eclipse plugin)" New topic
Author

maven create jar with dependencies (Eclipse plugin)

Zoltaan Szabo
Greenhorn

Joined: Jul 01, 2013
Posts: 18
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

Joined: May 14, 2008
Posts: 5823
    
    7

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


JBoss In Action
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30392
    
150

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Zoltaan Szabo
Greenhorn

Joined: Jul 01, 2013
Posts: 18
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

Joined: May 14, 2008
Posts: 5823
    
    7

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: maven create jar with dependencies (Eclipse plugin)