问题
I'm using NetBeans 6.8, Tomcat 6, and Maven 2.2 and want to see changes in my code immediately in the browser (showing http://localhost:8080) after saving the file.
The tomcat-maven-plugin has the following configuration:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.0-beta-1</version>
</plugin>
Following to the output it should perform in-place deployment.
What can I do to see changes in my Java code immediately in the browser?
回答1:
I spent a lot of time trying to get this work. Finally I just used jetty. I put this:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
<configuration>
<reload>automatic</reload>
<scanIntervalSeconds>5</scanIntervalSeconds>
</configuration>
</plugin>
Maybe all parameters are not correct, but then I created a custom goal of 'jetty:run' And I use that. I can't use the big green play button 'Run', but the jetty deploy works nicely and it hot deploys any changes in the Java classes.
回答2:
Take a look at JRebel. It should do what you want. Painlessly.
回答3:
Have a look at Hot Deployment of a Web Application with Maven in NetBeans. I also suggest to check Glassfish Hot Code Re-deployment (on Maven), especially the post about Compile on Save, and to try GlassFish, you may get better results.
回答4:
Use the tomcat:inplace
goal to invoke your webapp from its compiled classes and sources.
You may experience file locking problems on Windows. There are several workarounds, such as the antiJarLocking
contet attribute, but essentially this boils down to your webapp not properly shutting down, whch will eventually exhaust your VMs memory after several reloads. In my case, I was using Spring, and the "proper" fix was to add a destroy-method on some key beans so that the app was gracefully shutdown.
Maven Tomcat Plugin - tomcat:inplace
来源:https://stackoverflow.com/questions/2756891/incremental-hot-deployment-on-tomcat-with-maven-and-netbeans