File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

Maven add classes to jar

kartik krishnan
Ranch Hand

Joined: Nov 19, 2006
Posts: 63
Hi,

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.

Thanks,
Nathan Pruett
Bartender

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.


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

Joined: Jun 25, 2001
Posts: 16065
    
  21

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 ]

Customer surveys are for companies who didn't pay proper attention to begin with.
kartik krishnan
Ranch Hand

Joined: Nov 19, 2006
Posts: 63
Well,

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

My apologies.

Krishnan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Maven add classes to jar