Ant-Prompted Deployment from NetBeans IDE 4.1

Yesterday I found CoolBoy's blog, with an extremely interesting entry called "On the fly" deployment under NetBeans. Before coming across that blog entry, I never knew that Ant has its own input handler, as well as one or two conditional tags. So, using the input handler and the conditional tags, this is the dialog box that appears when I choose "Run Project" in a free-form project's contextual menu:

In standard projects, I could add the target that creates the above dialog box to the -post-dist target, as demonstrated in previous blog entries.

This is the Ant target that creates the dialog box and sets a property depending on which server I select:

<target name="Select-a-Server" description="Select One of 5 Servers">

  <input message="Where do you want to deploy to?"
          validargs="JBoss,Tomcat,SJS Application Server,WebLogic,WebSphere" 
        addproperty="server.name"
       defaultvalue="SJS Application Server"/> 
         
  <condition property="choose.JBoss">
       <equals arg1="JBoss" arg2="${server.name}"/>
  </condition>
         
  <condition property="choose.Tomcat">
       <equals arg1="Tomcat" arg2="${server.name}"/>
  </condition>
       
  <condition property="choose.SJS">
       <equals arg1="SJS Application Server" arg2="${server.name}"/>
  </condition>
         
  <condition property="choose.WebLogic">
       <equals arg1="WebLogic" arg2="${server.name}"/>
  </condition>
       
  <condition property="choose.WebSphere">
       <equals arg1="WebSphere" arg2="${server.name}"/>
  </condition>
                            
</target>
And here are two of the five targets for deployment, based on whether a property has been set or not. For example, if the choose.JBoss property is set in the previous target, then -- and only then -- will the Copy-to-JBoss target below be executed. This is all thanks to the if="choose.JBoss" attribute in the target declaration:

<target name="Copy-to-JBoss" depends="Select-a-Server" if="choose.JBoss" description="JBoss">
            
  <copy file="${dist.home}/${app.name}-${app.version}.war" todir="${build.dir.jboss}"/>
      
</target>
      
<target name="Copy-to-Tomcat" depends="Select-a-Server" if="choose.Tomcat" description="Tomcat">
            
  <copy file="${dist.home}/${app.name}-${app.version}.war" todir="${build.dir.tomcat4}"/>
      
</target>

Finally, to create a single target that bundles the targets above together -- so that they can all be invoked from the same menu item in a free-form project (or as part of the -post-dist target in standard projects) -- the following needs to be added:

<target name="Deploy" depends="Copy-to-Tomcat,Copy-to-JBoss" description="Deploy"/>

That's it. Of course, I haven't added the targets above to the current project's build.xml, but to a project-independent build.xml, which I import into the build.xml of any project that needs it. I think its all pretty cool because this way the same WAR file can be deployed wherever I want, based on a choice I make when prompted by Ant. And everything is invoked from one single menu item in NetBeans IDE 4.1. Or, I can just press F6 to invoke the dialog box. So now, when I set up the IDE as described in a recent blog entry, I just press F6 whenever I want to deploy, I choose my server from the input handler, and then I can view the result in the Favorites window right away (click to enlarge):

You could even go a step further -- append one extra statement to the Copy-to-XXX target and then you'll launch the IDE's default browser and open the deployed application in it. For example, for JBoss, you'd use a target as simple as the following:

<target name="Copy-to-JBoss" depends="Select-a-Server" if="choose.JBoss" description="JBoss">
            
  <copy file="${dist.home}/${app.name}-${app.version}.war" todir="${build.dir.jboss}"/>
  <nbbrowse url="http://localhost:${port.number.jboss}/${app.name}-${app.version}"/>
      
</target>

So, the above target is invoked as soon as you select 'JBoss' in Ant's input handler. And, as soon as you've deployed the application to JBoss, you can just go down the list in the input handler and deploy the same WAR file to another server. Each time, you'd see the result straight away because the browser is launched and the application is displayed. Ant rocks. So does NetBeans IDE. Thanks, CoolBoy, for your great tip.

Comments:

copy files tools http://www.yaodownload.com/utilites/file-disk-management/filemonkey/

Posted by jim on April 17, 2006 at 11:46 AM PDT #

Hello
I'm begining with ant appache.
I'd like list a directory and since this list select one or many documents. Like this but it's not ok:
<foreach target="bar" param="theFile">
<fileset dir="\\espacecomete\MC2\Rfrentiel documentaire\Arborescence MC2\06_Déploiement\50_Packaging\10_Livraison\${lot}/${date}" casesensitive="yes">
<include name="**/*.*"/>
</fileset>
</foreach>
</target>

<target name="bar">
<echo message="${theFile}"/>
<copy todir="fiche_livraison/" flatten="true"/>

Posted by guest on August 27, 2013 at 07:20 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
23
24
25
26
27
28
29
30
   
       
Today