File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Ant, Maven and Other Build Tools and the fly likes Maven add classes to jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Maven add classes to jar" Watch "Maven add classes to jar" New topic

Maven add classes to jar

kartik krishnan
Ranch Hand

Joined: Nov 19, 2006
Posts: 63

I am a Maven newbie so I would like to seek some help there. I have just joined a new project. It's structure unlike what is advised in all the Maven tutorials.

I would like to build the project structure which is defined as follows

Project Home . We have two folders under that

java and unittests.

Out requirements are that we would like to build a module.jar which holds all the class files including all the dependencies unjared and put into the single jar.

I am unable to figure out how to do this. I have looked at the Maven forums but unfortunately, I can not understand how to do this.

Please help me here.

Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

You don't define the directory structure and have Maven build your project... you have Maven build the directory structure and fit the parts of your project into the pre-determined locations.

It *is* possible to change the directory structure, but more problems than it is worth... and not guaranteed to work with all Maven plugins.

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

Nate's right. You CAN override the standard Maven directory conventions, but you'd probably regret it. I don't like them myself, but at least they're a standard that anyone can come in and take over the project with minimal learning.

The standard project structure for a JAR project looks something like this:

If you explode your dependency classes and put them in the main resources directory, they should copy into the final jar.

How you get them exploded is up to you. If you are working with a fixed set of jars, you can put them in a library directory, write an ant sub-task to explode them and let Maven take over. If you're attempting to use Maven-managed libraries, you'd probably have to do more work (or copy them into the above-mentioned library source directory).

There MIGHT be a jar-combiner Maven option, but I don't know of any. Not that that means much.
[ February 05, 2008: Message edited by: Tim Holloway ]

An IDE is no substitute for an Intelligent Developer.
kartik krishnan
Ranch Hand

Joined: Nov 19, 2006
Posts: 63

I saw this link Maven Build Settings and I assumed that it was possible.

My apologies.

I agree. Here's the link:
subject: Maven add classes to jar
It's not a secret anymore!