wood burning stoves 2.0*
The moose likes Ant, Maven and Other Build Tools and the fly likes What does maven Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "What does maven "packaging = jar" mean ?" Watch "What does maven "packaging = jar" mean ?" New topic
Author

What does maven "packaging = jar" mean ?

jay vas
Ranch Hand

Joined: Aug 30, 2005
Posts: 407
Hi guys : I've been using maven2 to manage dependencies for a while, it works well. I wanted to expand my use of maven to do more than just dependency management.... That is, I want it cover my deployment and testing needs.

However, I was confused about 3 things (I'm using the M2 plugin in eclipse, which very nicely merges maven into the natural eclipse build process, making it somewhat easy to be an ignorant maven user).

1) I never quite know what Maven means by "<packaging>jar</packaging>" .... Is it actually creating a Jar ? If so where is that jar being stored ? I'm also wondering the same thing for the war packaging command ... where is the "war" going ?

2) Is there a way to directly invoke JUnit tests from Maven by simply editing the Pom file ? I know that you can add some JUnit details using the
using the <build> tag, but I'm not sure how this relates, sequentially, to the overall maven compilation process.

Any suggestions on a good, project based maven / eclipse / junit tutorial would be nice also.

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15962
    
  19

Maven produces artefacts, and the "maven package" goal is the one that will compile the code, gather the resources, run the unit tests and build a deployable artefact (JAR, WAR, EAR, etc.).

The products of Maven are always written to the "target" directory. "mvn clean will erase these products, so I generally build a package using the command "mvn clean package".

"packaging jar" means quite simply that the goal is to produce a jar file in the target directory. "packaging war" would build a WAR file.


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

Joined: Aug 30, 2005
Posts: 407
That answers the war/jar question. Thanks!!
I was still wondering if there is a way to (by simply editting the pom) add all unit tests in a package to the build workflow ?

i.e. Is there a tag for this that I can add to
The <packaging> directive?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15962
    
  19

The maven "package" goal automatically runs unit tests, if you have any defined in your project. You need to add a junit dependency in "test" scope in order to select the Junit jar needed to run the tests, but it's mostly Just Magic.

You should put source for JUnit tests in the src/test/java subdirectory tree.
Abhijith Prabhakar
Ranch Hand

Joined: Dec 29, 2006
Posts: 56
Maven has a build lifecycle and phases. Depending on the packaging type you choose different phases are executed. Have a look at this link for more details
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: What does maven "packaging = jar" mean ?
 
Similar Threads
maven and Junit Tests
Mojo encountered an error while executing:
Trying to build with maven => package my.external.package does not exist
jsf + seam web application hotdeployment
problems with ant ftp task in maven