April 2009 Archives

Appframework, Maven, JavaRebel and NetBeans

I've tried to play around with various setups of Maven projects in NetBeans, testing "Compile On Save" primarily. The traditional CoS in NetBeans will redeploy your webapp or quickly rerun the application (without recompiling the sources). I've tested a bit more IDE independent setup here, described in few simple steps, hopefully useful to someone.

0. Install the latest dev binaries of upcoming NetBeans 6.7 (future beta or existing M3 shall also do, no guarantees for 6.5). Also download the Javarebel application from zeroturnaround.com

1. First take the appframework archetype and create a sample project we will be playing around. In Netbeans 6.7 builds, the archetype shall be available in the New Maven project creation wizard in a privileged location.

2. Open the pom.xml file for the project and add a profile for JavaRebel there.

<name>Zero turnaround repo</name>
<echo file="${project.build.outputDirectory}/.netbeans_automatic_build">Generated by maven build for javarebel in netbeans.</echo>

The configuration performs 2 tasks. It generates the rebel.xml file required by the Javarebel agent to find the output folders of the project in the resulting running application. Second, it generates a file in the output area of the project that tells NetBeans java support to copy the class files on saving.

3. Now you can Enable Configurations in the Project properties, activate the rebel profile there and for that profile/configuration, add additional VM options for running the application (the Run panel in project properties dialog)
For me it was:

-noverify -javaagent:/home/mkleint/javatools/javarebel/javarebel.jar

4. Build & Run the Application. If you've done things right, you should see in the output that the JavaRebel agent is running.If you open the application's AboutBox form and move stuff around, you should be able to see the changed propagated on Save in the IDE. Oups, You actually won't :) The showAboutBox() method the View class is caching the created about box, therefore the old layout persists. Once you remove the caching (even already in running application), you will see any changes in the AboutBox in the running application immediately.

5. Enjoy.

Fixing Maven POM inheritance chain

| 1 Comment

Whenever you have a Maven project inheriting from a parent POM, you should make sure the parent is accessible from the sources via the project/parent/relativePath element. The default value is "../pom.xml", the direct parent folder. The sources version will only be used if the coordinates match, of course. Eg. your project/parent /version element value needs to match the parent's version element.

If one of the conditions is not met, you end up resolving the parent POM from repositories defined in the current project. That might be the right thing in some cases, but sometimes it will prevent you from building the project separately (without having built all the parent beforehand) and also loading of the project in the IDE. In NetBeans, this is one of the reasons for the famed "Badly formed Maven project" error message. Even if it resolves properly from repositories, you might end up in with inconsistent data if some of your projects use the parent from local repository and some from sources.

A way to double check in NetBeans how your projects resolve is to show the "POM Inheritance" navigator view while having the pom.xml file focused in editor.
In this screenshot, I have opened the v3/common/glassfish-api/pom.xml file from the latest GlassFish svn checkout. The navigator view is in the left bottom area. It displays the project's POM inheritance, the current pom at the top, the direct parent below it and so on. Any parent marked with "(read only") is only resolvable from local and remote repositories. In this example, that might be fine for the ultimate root (pom - 3), but it's most likely wrong for any SNAPSHOT parents, like glassfish-parent.

PS: The NetBeans 6.7 Milestone 3 is out. Check it out.

About this Archive

This page is an archive of entries from April 2009 listed from newest to oldest.

March 2009 is the previous archive.

July 2009 is the next archive.

Find recent content on the main index or look in the archives to find all content.