Monday Apr 11, 2005

Adding Menus to NetBeans IDE 4.1

Until a few minutes ago, I thought that a shortcut to an Ant target can only be added as a menu item to one of the IDE's default menus, such as "File", or "Build", or "Tools". However, I've just discovered that you can create your own menus, and specify where in the menu bar you want to place them, so that when you create a shortcut, you can add it to your own menu (instead of one of the IDE's default menus).

And there are two ways of doing this. The "official" way is to go to Tools > Options, then IDE Configuration > Look and Feel > Menu Bar. And then right-click the Menu Bar node and choose Add Menu. You can also add submenus, by right-clicking the node of the menu and choosing Add > Menu. (And you can also add separators.) And, when you right-click a node, you can choose Change Order, so that you can reorganize the items within the node. (The "unofficial" way of doing this is to go the IDE's user directory, and then to dev/config/Menu. In this folder, you can add as many menus and menu items as you like, as folders and subfolders, then restart the IDE, so that the IDE can load the new menus.)

Once I had created a new menu called "External Servers", with the submenus "JBoss" and "Tomcat 4", I right-clicked my IDE-wide targets (for running and stopping JBoss and Tomcat 4, as well as one for testing JBoss) in the Projects window, and added them to my new menus. This is how it looks in the Options window:

And this is what my cool new menu items look like in the IDE:

Learning about Build Targets in NetBeans IDE 4.1

I realized that having a single menu item for two different actions (deploying to JBoss and deploying to Tomcat 4) is a bit counter-intuitive. Each time I needed to change servers, I had to change properties so that the target would work for the appropriate server. So, I decided to create separate deployment targets. This meant that I also had to create separate targets for building the application -- if I want to deploy to JBoss, I want to build my application to a JBoss-specific directory and if I want to deploy to Tomcat 4, I want to build my application to a Tomcat-4 specific directory. So, this is my build target for Tomcat 4:

 <target name="aaa_Build-To-Tomcat4" description="Build to Tomcat4">
       <copy todir="${build.classes.dir.tomcat4}">
            <fileset dir="${src.root}" excludes="${build.classes.excludes.tomcat4}"/>
       </copy>
       <copy todir="${build.web.dir.tomcat4}">
            <fileset dir="${web.root}" excludes="${build.web.excludes.tomcat4}" />
       </copy>
 </target>
And my deploy target is still as follows:

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

And they use the following properties:

#The Tomcat 4 directory where everything is copied to:
 build.dir.tomcat4=c:/Program Files/Apache Group/Tomcat 4.1/webapps/${ant.project.name}

#The Java classes, where they go, and what to exclude:
 src.root=src/java
 build.classes.dir.tomcat4=${build.dir.tomcat4}/WEB-INF/classes
 build.classes.excludes.tomcat4=\*\*/\*.java,\*\*/\*.form

#The web files, where they go, and what to exclude:
 web.root=web
 build.web.dir.tomcat4=${build.dir.tomcat4}
 build.web.excludes.tomcat4=${build.classes.excludes.tomcat4}

#Port number:
 port.number.tomcat4=8085
The key to the whole puzzle was discovering that ant.project.name gets the project's name (which is set in project.xml). What is also pretty cool is that the IDE can generate a build script for you, which means that you can see how it is structured, so that you can create one yourself, even if you are a complete novice in Ant, like me...

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