Over a million developers have joined DZone.

"Deploy on Build" using JBoss Application Server

· Java Zone

Microservices! They are everywhere, or at least, the term is. When should you use a microservice architecture? What factors should be considered when making that decision? Do the benefits outweigh the costs? Why is everyone so excited about them, anyway?  Brought to you in partnership with IBM.

Recently, I had asked a question on NetBeans Forums on the "Deploy-on-Save" feature supported by NetBeans 6.5 IDE. Well, I know I can’t configure build script in such a way, so that it can deploy on save. However, I found a trick to deploy the war file everytime I build OR clean and build.

Brief Overview

This trick will save your time and do lot more stuff with an existing shortcut, which you might have missed otherwise. Actually, I was working on a "Dynamic Web project" in Eclipse IDE where I was supposed to make use of its 2.0.0.Beta2 version using JBoss 4.0.5 GA (with Java EE Platform set to "J2EE 1.4" ). Eclipse was so slow and its editor support for JSP pages was doing no good. Probably, if I could have used a new release of Eclipse, then that might have helped. Still, I am not sure, its just an assumption.

Also, everytime I made changes I had to first right-click project node, then select "Run As > Run on Server" and if I made any changes during runtime, it was not deploying automatically. Although, "Project" menu showed project to be build automatically . So, I had to repeat the cycle again and again.

Due to the above stated issues/problems, I decided to import the complete project into NetBeans 6.5 IDE. Import was successful and I added the JBoss server into NetBeans IDE ("Tools > Servers" ). Now, project is successfully building and deploying. Its absolutely working fine.

Now, NetBeans 6.5 didn’t supported "Deploy on Save" feature for the web applications that were using JBoss Application Server (I am referring to the above release), as per my recent observation.

Then, when I made changes to the webpages in the earlier mentioned project, I still couldn’t deploy on save/build. So, I had to right-click the "Project Node" and click "Deploy". This cycle is shorter one, still frustating if one makes changes frequently.

Tricks..

Now, open your project’s build.xml file and here’s the trick you need to do;
Add the following tags;

  <target name="-post-dist">
<echo>Automatic-deploy</echo>
<!--antcall target="run-deploy" inheritrefs="-init-deploy-ant"/-->
<antcall target="run-display-browser" inheritrefs="-init-deploy-ant"/>
<echo>Done...</echo>
</target>

below;

  <import file="nbproject/build-impl.xml"/>

This was done to override the above mentioned target present in build-impl.xml file, but thats empty.

    <target name="-post-dist">
<!-- Empty placeholder for easier customization. -->
<!-- You can override this target in the ../build.xml file. -->
</target>

Now, whenever you do "Shift-F11" or "F11", it will "clean & build" or "build" respectively and then, deploy the project to the server.

Tips to Remember..

If you replace the following tag;

    <antcall target="run-display-browser" inheritrefs="-init-deploy-ant"/>

with

    <antcall target="run-deploy" inheritrefs="-init-deploy-ant"/>

The moment you use "Shift-F11" or "F11", the project will deploy the "war" file, however it will not run the browser for you, as it was doing earlier. If you have better solution, or encounter some problems, do let me know. Hope this helps.

Enjoy NetBeaning!

 


References;

  1. NetBeans Community Docs Tips and Tricks
  2. My Blog's 13th Tips and Tricks
  3. NetBeans Weekly Issue #383

Discover how the Watson team is further developing SDKs in Java, Node.js, Python, iOS, and Android to access these services and make programming easy. Brought to you in partnership with IBM.

Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}