Thursday, October 23, 2008

Netbeans 6.1 EAR Autodeploy with Glassfish

This is a hybrid of the post: http://www.nabble.com/In-NetBeans6.0.1-with-GlassFish-V2-the-web-application-cannot-auto-deploy.-td15853830.html

Basically, when I used eclipse (myeclipse), I could edit a jsp and it would automatically be updated when I refreshed the browser. It wasn't just jsp's, I could edit managed beans, helper classes, anything except the config files and they would magically appear deployed. Sometimes if I saved with an error in the class it would kill the app and I would have to fix the error and redeploy manually.

When I switched to Netbeans, I lost this nice feature. I was forced to "undeploy/redeploy" each time I made a small change. What a pain.

So I googled and came up with this hybrid solution:

1. Turn off deployment in Netbeans to glassfish: Tools -> Servers, then chose GlassFish, then Options. Uncheck "Directory Deployment Enabled"

2. Edit the project's build.xml file and add a target to copy a newly created ear file to glassfish's autodeploy directory:


<target name="post-dist">
<echo>post dist copy ear</echo>
<copy file="dist/[project_name].ear"
todir="/Applications/NetBeans/glassfish-v2/domains/domain1/autodeploy" />
</target>


That's it, now when I chose "Clean and Build" all changes are autodeployed. I know that you can make this target a bit more generic, but I'll leave that to you.

Enjoy!