Structuring Ant Targets in the NetBeans IDE

I've created one build script for IDE-wide targets (for running and stopping Tomcat 4, for accessing the Tomcat users file for Tomcat 5.5, and for easy access to Star Office) and a separate build script for project-specific targets. I'm keeping these two build scripts separate so that (1) I know where to look for my targets and (2) I only need to import the project-specific build script into any project-level build script that might need it.

So, for example, in the illustration below, I only need to import project-specific-targets.xml into a project's build.xml file, because the IDE-wide targets are irrelevant on project-level. The aaa_DeployToTomcat4 task is quite useful because the IDE does not officially support Tomcat 4, but thanks to Ant-integration anything can be integrated into the IDE. (I've prefaced the deployment target for Tomcat 4 with "aaa_" so that it ends up at the top of the list in the build.xml files that import it):

This is what aaa_DeployToTomcat4 looks like:

<target name="aaa_DeployToTomcat4" description="Deploy to Tomcat 4">
    <exec executable="C:\\Program Files\\mozilla.org\\Mozilla\\mozilla.exe">
	<arg value="http://localhost:8085/${project.name}/${client.urlPart}"/>
    </exec>
</target>

(When I installed Tomcat 4, I set the port number to 8085, which is easy to remember because it's just after the IDE's bundled Tomcat's port number 8084, and because Tomcat's default port number is 8080 which is the same as the Sun Java System Application Server.)

And, by the way, this is how I start Tomcat 4 (RunTomcat4 in ide-wide-targets.xml):

<target name="RunTomcat4">
    <exec executable="c:\\Program Files\\Apache Group\\Tomcat 4.1\\bin\\startup.bat">
        <env key="CATALINA_HOME" value="c:\\Program Files\\Apache Group\\Tomcat 4.1"/>
        <env key="CATALINA_BASE" value="c:\\Program Files\\Apache Group\\Tomcat 4.1"/>
    </exec>
</target>
So, to be able to re-use aaa_DeployToTomcat4, I do the following in WebApplication1:

  1. Add the following to build.xml:

    <import file="../ProjectAntTargets/project-specific-targets.xml"/>
  2. Change the first and add the second property below in the nbproject/project.properties file:
    • build.web.dir=c:/Program Files/Apache Group/Tomcat 4.1/webapps/${project.name}
    • project.name=WebApplication1

  3. Right-click the project node, choose Properties, click Run, and type the starting page in the Relative URL field. (This field sets the client.urlPart property in the nbproject/project.properties file.)
Finally, you must make sure that the properties set in nbproject/project.properties are available to aaa_DeployToTomcat4, so add this to the top of the aaa_DeployToTomcat4 target:

<import file="../WebApplication1/nbproject/project.properties"/>
And then you can create shortcuts and deploy to Tomcat 4 using the reusable aaa_DeployToTomcat4 target. (And when I delete WebApplication1, as I am bound to do sooner or later, I'll not destroy aaa_DeployToTomcat4, because it's in a separate build script.) There's probably better ways of doing this. For example, maybe the project.properties file should be shared as well, but I think it's all pretty cool, however you look at it.

Comments:

Good insight. I was trying to integrate netbeans with resin. I found the ant tagets use ful to run resin from netbean. An clarification Is if possible to debug an jsp/servlet from netbeans with resin Thanks

Posted by Mat on December 13, 2005 at 11:17 PM PST #

ghjhjjdghj

Posted by guest on December 17, 2005 at 01:52 PM PST #

To Integrate Resin with netbeans Use the following build.xml file 1. In the netbean,create a build.xml file and add the following target to the build.xml. <target name="run-display-browser" description="Run on Resin 3.0.15"> <property file="nbproject/project.properties"/> <nbbrowse url="http://localhost:8080/${project.name}/${client.urlPart}"/> <!-- "http://localhost:8080/FirstWebApp"/>--> </target> <target name="run-deploy" description="Deploy to resin"> <property file="nbproject/project.properties"/> <copy file="dist\\${war.name}" todir="C:\\resin-3.0.15\\webapps"/> </target> <target name="RunResin3015"> <exec executable="C:\\resin-3.0.15\\httpd"> <env key="RESIN_HOME" value="C:\\resin-3.0.15"/> <env key="RESIN_BASE" value="C:\\resin-3.0.15"/> </exec> 2. To start the server, click on the Files tab in netbeans and expand the build.xml file. Right click the RunResin3015 target and choose run target to start the resin server. 3. The web server will start with a dialog popping up.

Posted by Mathew on February 09, 2006 at 10:32 AM PST #

<target name="run-display-browser" description="Run on Resin 3.0.15"> <property file="nbproject/project.properties"/> <nbbrowse url="http://localhost:8080/${project.name}/${client.urlPart}"/> <!-- "http://localhost:8080/FirstWebApp"/>--> </target> <target name="run-deploy" description="Deploy to resin"> <property file="nbproject/project.properties"/> <copy file="dist\\${war.name}" todir="C:\\resin-3.0.15\\webapps"/> </target> <target name="RunResin3015"> <exec executable="C:\\resin-3.0.15\\httpd"> <env key="RESIN_HOME" value="C:\\resin-3.0.15"/> <env key="RESIN_BASE" value="C:\\resin-3.0.15"/> </exec> 2. To start the server, click on the Files tab and expand the build.xml file. Right click the RunResin3015 target and choose run target to start the resin server.

Posted by guest on February 09, 2006 at 10:34 AM PST #

<target name="run-display-browser" description="Run on Resin 3.0.15"> <property file="nbproject/project.properties"/> <nbbrowse url="http://localhost:8080/${project.name}/${client.urlPart}"/> <!-- "http://localhost:8080/FirstWebApp"/>--> </target> <target name="run-deploy" description="Deploy to resin"> <property file="nbproject/project.properties"/> <copy file="dist\\${war.name}" todir="C:\\resin-3.0.15\\webapps"/> </target> <target name="RunResin3015"> <exec executable="C:\\resin-3.0.15\\httpd"> <env key="RESIN_HOME" value="C:\\resin-3.0.15"/> <env key="RESIN_BASE" value="C:\\resin-3.0.15"/> </exec>

Posted by guest on February 09, 2006 at 10:42 AM PST #

Hey Mathew, you say "use the following build.xml file", but I don't see a build.xml file. I'd be interested in trying it and also the steps you describe here. Maybe you could send it to my e-mail address: geertjan.wielenga@sun.com and then maybe I'll blog about it!

Posted by Geertjan on February 09, 2006 at 05:49 PM PST #

Thnx!!! is some tricky to make it work, but finally i can do it \^\^

Don't forget the </target> after </exec>

To find the build.xml just use Ctrl+Shift+F, then put "build.xml" in "File Name Patterns" input (no quotes)

Posted by Roge Rodríguez on May 10, 2008 at 04:02 PM PDT #

Hi,

I'm trying to run resin 3.0.25 from within netbeans 6.1 (6.5) so that I can debug, hot-deploy stuff etc. Is it possible? If so, could you please post detailed instructions on how to do that

Thanks!
V

Posted by vlad on September 16, 2008 at 09:54 AM PDT #

What the "World Needs Now" is another Netbeans 6.1 "add server" option (e.g. Resin 3.1.6)

No plugins found anywhere. Hmmm
Can anyone hack Netbeans 6.1 to include Resin as an option?

Thanks
newbean

Posted by newbean on September 20, 2008 at 07:16 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
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 2014
SunMonTueWedThuFriSat
  
12
13
14
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today