Thursday Apr 07, 2005

Customized Contextual Menu for Deploying from NetBeans IDE 4.1

After creating a property-determined Ant target that deploys a NetBeans IDE project to Tomcat 4 or JBoss (see yesterday's blog entry), I wanted to be able to access the target from a project's contextual menu. This is only possible in a free-form project. So I created a free-form project from the build-impl.xml file that the IDE creates for you when you create a standard project. This way, I've got the best of both worlds -- all the standard targets generated by the IDE together with the possibility of extending the project even further, giving it more freedom, thanks to the facilities offered by the free-form project. So here is my contextual menu:

I guess a better name for the contextual menu would be something like "Deploy to External Server", but what if I were to forget which servers are made available in the properties file? At least this way I know what's there.

Tomcat 4, JBoss, and Ant in the NetBeans IDE

So now I have an Ant properties file with the following content:

# Tomcat 4
#port.number=8085
#build.web.dir=c:/Program Files/Apache Group/Tomcat 4.1/webapps/${application.name}
#application.name=WebApplication1

# JBoss
port.number=8082
build.web.dir=C:/jboss/jboss-4.0.1sp1/server/default/deploy/${war.name}
application.name=WebApplication1
war.name=WebApplication1.war
And my Ant script contains one target:

<target name="aaa_Deploy-To-Tomcat4-or-JBoss" description="Deploy to Tomcat 4 or JBoss">
  <nbbrowse url="http://localhost:${port.number}/${application.name}"/>
</target>

When I import (1) the Ant script containing this target and (2) the file defining the target's properties into a NetBeans IDE project's build.xml file (or whatever the local Ant build file is called), I only have to change the handful of properties in the external Ant file's properties file to be able to deploy to either Tomcat 4 or JBoss, after building the project to the build.web.dir applicable to the server in question. (Of course, I also have targets that start and stop Tomcat 4 and JBoss, but these are IDE-wide targets.) This is how I import the Ant script and properties file (they're both in a folder called "IDETargets", which is a different folder to where my IDE projects are stored -- by storing my re-usable targets in a separate folder I'm protecting them from my occasional over-zealous deletions):

<import file="../../IDETargets/ProjectAntTargets/project-specific-targets.xml"/>
<property file="../../IDETargets/ProjectAntTargets/nbproject/project-specific-targets.properties"/>

Here are the 1000 words in a picture:

The cool thing about this is that I now have a separate Ant script that contains all the information I need for deploying to Tomcat 4 or JBoss. Whenever I create a new web application, all I need to do is import the external Ant script and properties file into the new web application's own Ant script, tweak the properties in the external Ant script's properties file, and that's all. No deployment-related information is defined within an individual NetBeans IDE project, and so nothing is lost (and everything is re-usable) when I delete/lose/break an individual NetBeans IDE project.

About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2005 »
SunMonTueWedThuFriSat
     
1
2
8
9
10
14
16
18
22
23
29
       
Today