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 .
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.
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>
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"/>
<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.