java left logo
java middle logo
java right logo

Home arrow Other API Tips
Main Menu
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog

Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews

Registered Users: 4116
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
Extending the Build Process E-mail
User Rating: / 2

In today's tip I will show you how to extend the NetBeans build process on a simple example.

Some background first - NetBeans utilizes Ant as it's primary project engine. So when you build any project the IDE executes Ant. Other Java IDEs use as primary project systems different engines, developed specially for these IDEs. That was the case with NetBeans 3.x as well but with NetBeans 4.0 it was changed to Ant which is de facto a standard for building Java applications.

Ant is used similarly to GNU make to automate the build process. It can also handle build dependencies but unlike make it is completely plaftorm and shell independent (it's java-based), it's configuration is XML-based and can be extended easily. You can read more about Ant in it's user manual.

Back to the tip - let's say I want to copy the jar file which is built with my project to a network share - for instance to publish it as a bleeding edge development build of the application. I want to create a backup copy of it's sources as well. Such tasks can be automated with NetBeans and Ant very easily.

To do this I need to override the build.xml file which is stored in the main directory of my project. The build.xml file by default just includes a file called build-impl.xml, located in nbproject subdirectory. Build-impl should not be touched (it is generated automatically), instead the targets in build.xml need to be overriden.

So I override the "-post-compile" target to create an archive with my sources using tar and gzip tasks. I want Ant to create a subdirectory called by current date and name the archive according to the date as well. To do that I at first initialize the DSTAMP variable using a task called . I also override the "-post-jar" target to copy the jar which is created automatically in the dist directory:

   <target name="-post-compile">
        <tar tarfile="${dist.dir}/sources.tar" basedir="${src.dir}"/>
        <gzip zipfile="${dist.dir}/sources.tar.gz" 
        <copy file="${dist.dir}/sources.tar.gz"            
        <delete file="${dist.dir}/sources.tar"/>     
        <delete file="${dist.dir}/sources.tar.gz"/>
    <target name="-post-jar">
        <copy file="${dist.jar}/" tofile="h:\${DSTAMP}\app-${DSTAMP}.jar"/>

From now on everytime I build the project a copy of the jar and an archive with soures are created in a directory with current date on a network share. To achieve that I only needed to add few lines into the build.xml file (yeah, I know, you need to know which lines to add... ;-) If you didn't play with Ant yet, I suggest to try it, because it can help you automate a lot of tasks you may be doing manually. It's sometimes funny how much time we can give away to avoid doing a manual task - but with Ant this mostly pays off. Really.

Source: Roumen's Weblog

 Related Tips

< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.

Name (required)

E-Mail (required)

Your email will not be displayed on the site - only to our administrator

Comment Enable HTML code : Yes No

java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008
Java is a trademark of Sun Microsystems, Inc.