Showing posts with label maven. Show all posts
Showing posts with label maven. Show all posts

Wednesday, December 16, 2009

Building a self contained Jar with Maven on Netbeans

Sometimes I need to build a Jar for distribution. A typically ideal type of Jar is one which can be executed from the command line:

java -jar ./myApp.jar

I have in the past used One-Jar which works nicely for this purpose, but now I'm using Maven as standard, this should be able to do this for me. And do it without IDE dependent plugins.

Today I'm going to build a jar with Eclipse. The project which I'm building is dependent on another local Maven project, and they both are dependent on locally and repository managed Jars.

Once all the dependencies are in the Maven Classpath Container, it is a matter of editing the pom.xml file which dictates the build process.

to this I added a plugin - in the section of the node:

  <artifactid>maven-assembly-plugin</artifactid>
  <configuration>
    <descriptorRefs>
      <descriptorRef>jar-with-dependencies</descriptorRef>
    </descriptorRefs>
    <archive>
      <manifest>
        <mainClass>net.crisppacket.myApp</mainClass>
      </manifest>
    </archive>
  </configuration>

so now, issuing (from the command line):

mvn assembly:assembly

will create a Jar for you. I got this far with the assistance of the excellent KSB's Maven Notes.

Now, in Netbeans, you can add a Custom Goal. Right click on the project you want to build, select 'Custom->Goals...' and then in the Goal field type:

assembly:assembly

OK. Now you can select this Goal (using the same mouse navigation) and it will build you a Jar. Hopefully.

Wednesday, November 25, 2009

maven, fedora.

I've been tipped that Maven is worth the learning curve.

I had a go, on Fedora 11. I can't wait for Fedora 12.

My first tip, is download and install locally: maven 2.2.1.
Install this into /usr/local/maven...

Use that in your Eclipse/NetBeans.

I'm on holiday for a few days... but I will post on how to get Eclipse and NetBeans building a distributable (all dependencies included) jar from the IDE when I return.

In conclusion: Maven is worth the learning curve.

UPDATE: After reflecting on actual use of Maven, I can add the following:

  1. Because it manages the build process, the IDE does not manage the build process. This means that you reduce your dependence on a given IDE. The project I'm working on is now developed by NetBeans and Eclipse folks. At the same time.
  2. Because it manages the build process, you are not dependent on IDE specific tools to build your distribution Jar. I like One-Jar but it is an extra dependency.
  3. By allowing you to collect all dependent code in your own repository, Maven enables a new level of technical management to be applied across a project, group, division etc.