X

Geertjan's Blog

  • April 11, 2005

Learning about Build Targets in NetBeans IDE 4.1

Geertjan Wielenga
Product Manager
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...

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.