Integrate JBoss AS Maven Plugin with NetBeans

Deploying JEE Artefacts such as EAR Files to a JBoss EAP Server instance is unfortunately not working with NetBeans out-of-the-box. The NetBeans Application Server Plugin as well as the additionally available Wildfly Plugin do not help. If you are a corporate developer whose company licensed a fairly new JBoss EAP 6.2.x (at least at the time of writing this entry) – you’re out of luck.

Fortunately NetBeans excellent maven integration comes to the rescue in form of the JBoss Application Server 7 Maven Plugin. There is also Wildfly Maven Plugin available. Just add the following lines to your pom.xml’s “plugins” section (in my case a maven EAR module):

1
2
3
4
5
6
7
8
9
10
11
  <plugin>
    <groupId>org.jboss.as.plugins</groupId>
    <artifactId>jboss-as-maven-plugin</artifactId>
    <version>7.6.Final</version>
    <configuration>
      <hostname>localhost</hostname>
      <port>9999</port>
      <username>jbossadmin</username>
      <password>*******</password>
    </configuration>
  </plugin>

Hostname, port, username and password have to be changed according to your needs.
Now you have quite a few additional maven goals at hand – deploying, undeploying and redeploying as well as starting and stopping the JBoss EAP Server instance. I usually have an already running JBoss instance on my notebook, hence the deployment related goals matter to me:

  • jboss-as:undeploy — undeploys your already deployed artefact from the running JBoss instance
  • jboss-as:deploy — deploys the artefact that is generated by your maven project to the running JBoss instance
  • jboss-as:redeploy — redeploys your artefact

You could bind the redeploy goal to the packaging phase, so that every time the artefact is built, it is also redeployed to your local JBoss EAP Server instance. I prefer explicit execution of the redeployment goal. NetBeans offers two ways doing that:

Deploy through the NetBeans Navigator Window

Select the maven artefact project – in my case this is the pla-ear-2.0.0. The Navigator Window displays all maven goals that are not bound to maven life cycles. Double click the jboss-as redeploy goal and 8 seconds later, the artefact is deployed and ready to be debugged. At least when you have your debugger attached to the running JBoss EAP Server instance.

navigator-window-redeploy

Deploy with custom NetBeans Actions

I have three custom actions, that let me deploy, undeploy and redeploy the built artefact to my locally running JBoss EAP Server instance. The actions can be reached through a right click on the maven JEE artefact project node. It opens up the projects context menu. Here select the Custom entry, that again opens a sub-menu with all your custom NetBeans actions refering to maven jboss-as plugin goals.

context-menu

Set-up the goals as actions in the projects properties screen. Select the Actions category.

actions

With the Add Custom… button I created three additional actions: Deploy, Undeploy and Redeploy. For each action¬† fill in the relevant maven goal: jboss-as:deploy, jboss-as:undeploy and jboss-as:redeploy. These show up later under the projects context menus Custom entry.

Make sure to uncheck the Compile On Save checkbox! Otherwise NetBeans own server deployment mechanism interferes with the maven plugin:

compile-on-save

Happy deploying!