Download NetBeans!

20050406 Wednesday April 06, 2005

Sharing Ant Targets Across NetBeans IDE Projects

Some targets are not project-specific, but IDE-generic. For example, the target created in the previous entry gives one-click access to the tomcat-users.xml file from the IDE. This file shouldn't only be available from a specific project. I shouldn't have to cut and paste the target into each project's build script (neither should I have to run the target in one build script while working in another). So I've created a separate build script where I'll store all targets that are useful for all projects. Now, all I need to do is add the following line to one or more project's build scripts:

<import file="path-to-build-file/ide-generic-targets.xml"/>
Then, when I build the project, the targets from the IDE-generic build script are imported into the project's project-specific build script. It also means that when I delete a project, I won't be deleting a target that other projects (now or in the future) might find useful. I guess this solution is pretty obvious, but it took me a while to think of it...

NB: Maybe an even better solution is to create a web free-form project with a build script containing all the IDE-generic targets. That project could then have all these targets mapped to project commands, with shortcuts like buttons and menu items for actions such as opening external applications that are useful for all projects. Yup. That works. And is a much better solution:

Apr 06 2005, 08:36:26 AM PDT Permalink

Easy Access to Tomcat Users File from NetBeans IDE

Whenever I access the Tomcat Manager for the first time in a session, this little dialog box appears:

For details on this from Tomcat's site, click here.

What then happens is that I've got to dig into the IDE's user directory to find a file called tomcat-users.xml, which includes a user called "ide" (which is assigned the role of "manager") together with an IDE-generated password. The digging is a bit frustrating, so I'm using this Ant script instead:

<target name="ShowTomcatUsers">
  <property name="file" location="my-user-dir\jakarta-tomcat-5.5.7_base\conf\tomcat-users.xml"/>
  <exec executable="c:\Program Files\Vim\vim63\gvim.exe">
     <arg value="${file}"/>
  </exec>
</target>

I've just added it to the build.xml file, together with a shortcut so that whenever I need it I can just click a button or a menu item in the IDE to display the file:

Just one of the many benefits of Ant integration in the IDE...

NB: Because the authorization dialog box is modal, I need to click out of it and then use the shortcut to access the Tomcat users file. So I need to work out some way of calling the ShowTomcatUsers target automatically whenever the Tomcat Manager needs to be authorized. It could be called from the Run target, except that I haven't worked out yet how to test whether the Tomcat Manager needs a password. Only in that instance would the file need to be called. Apr 06 2005, 12:46:59 AM PDT Permalink