I am quite new to Java EE and have been struggling with the slowness of the deployment process, and wonder if I'm doing something wrong. I am experienced with Django where the changes to code immediately occur, and it seems that hot deploying Java EE applications are a bit confusing -- there are multiple things which claim to hot deploy (Glassfish, Eclipse manic hotdeploy, Jetty hotdeploy, JRebel etc.).
My project is a Maven project and I'm using Netbeans to deploy. The site uses Spring, JSF and Hibernate frameworks.
In Netbeans, Deploy on Save, according to the following screenshot seems to be enabled, but clicking/unclicking is not possible since it claims to get the info from my pom.xml (though there is no such field in my pom.xml (only dependencies)).
Now, changes to some files seem to be effective immediately. These include: - JSF files - Static files
Changes to following require deployment: - Any XML file - Any properties file, even localization properties files - Any java file
Changes to those require me to deploy manually and redeploying takes half a minute even though I currently have only 2-3 classes, basically a single user class and an authorization class. The project allows just logins at the moment, and despite this, the compilation takes around a few seconds; and the container (Glassfish) seems to consume around 600 MB of RAM and even gives PermGen errors after a few deployments and I need to kill the java process using Task Manager. (I have read that this is related to garbage collector leaking after each redeploy, and I have even used jhat to generate a profile, but was presented with a list of thousands of classes, my classes, Spring, Hibernate classes etc.)
I have heard about jrebel as well, and tried running it, but it seems that it is not compatible with my Netbeans version (7.0) and even though it seems to run, any modification to any java file still requires a redeploy.
Is there anything I can do to remedy these issues, or is it just normal in Java EE to wait for around 1 minute after each change to any Java file? This issue kills productivity significantly.
Here is my Glassfish output when deploying the application: http://pastebin.com/7FhZ6AVh
I've found neither credible nor official sources but since you have no answers I'd like to point out two things I've discovered.
The first is this FAQ on the NetBeans site describing how to turn on compile on save for a Maven project. It appears that this setting is off by default and only on by default for tests. For convenience:
Go to the project properties dialog, Compile panel, to turn it on for main source execution as well.
The second is, and I must stress that I don't quite understand this completely, there seems to be two different ways that NetBeans deploys a Web Application. The first way is an in-place deployment that appears to be the same as deploying a .war
file to the server manually. The second is an incremental deployment, which if it's anything like incremental compilation it means that when your app is hot-deployed you are only deploying the changed files.
The in-place deployment seems to be the default method of deployment when you either click Run
or Deploy
from the projects' context menu. The incremental deployment happens when your project is already deployed and you click Run
again (or use the Run
toolbar button).
I'd like to point out that the NetBeans FAQ, although on the netbeans.org website is not an official publication. Anyone can create a FAQ and the information can and will become obsolete without revision.
Edit: After a little reflection I've decided that the so called incremental deployment is not a different way of deployment it's just that the second time you Run
your application it does an incremental deployment.
Edit: Notice that the instruction above is pointing you to the Compile
panel as opposed to the Run
panel that you have selected in your screenshot. Here's my screen shot showing that you need to choose for both application and test execution
in the Compile
panel drop down and that the default is for test execution only
JRebel is compatible with NetBeans 7.0 (http://plugins.netbeans.org/plugin/22254/jrebel-netbeans-plugin) and in fact it is compatible with any IDE out there.
This is a great video by Geertjan Wielenga from the NetBeans team that walks through setting up JRebel on NetBeans 7.2.1 and GlassFish 3.1.2:
How to Get Started with JRebel in NetBeans IDE: http://www.youtube.com/watch?v=kveXKv2q4Ec
"Compile on Save" slowed things a lot for me, but another thing I have found out afterwards is the "Apply Code Changes" button in Netbeans, that is only visible in Debug mode. (The green button at the right in the picture)
This is useful to apply Java code changes; it doesn't work each time, but I think it works most of the time if the change is not a method addition and the bean is request scoped. I think this does what Compile on Save manually, but it's better than redeploying.
来源:https://stackoverflow.com/questions/7766635/redeploying-java-ee-applications-immediately