Integrating tomcat and eclipse as a hot-deploy env

2019-01-01 06:18发布

I would like to setup eclipse and tomcat in an integrated fashion such that changes to my JSPs and servlets(if possible) are reflected immedietely without requiring a deployment.

Ok, this is one of those questions that has plenty of answers all across the internet but they all seem different. (use Sysdeo plugin, use JBOss plugin, do stuff with an outdated Eclipse, use MyEclipse instead etc.) and I couldn't find 1 definitive resource to refer to. So for my benefit, what is the simplest and most recommended procedure to set this up ?

This assumes I have eclipse and tomcat running independently. I actually have managed to integrate them in a non-hot deploy fashion using instructions here : http://www.ibm.com/developerworks/opensource/library/os-eclipse-tomcat/index.html

Eclipse version Version: 3.4.2 (Ganymede) Tomcat v6.0.20

16条回答
旧时光的记忆
2楼-- · 2019-01-01 06:43

Are you open to using Jetty for development purposes?

If so, it's pretty simple to use with Maven - just run mvn jetty:run

查看更多
倾城一夜雪
3楼-- · 2019-01-01 06:45

In servers view , create a new server , don't add any resource (project) to the server yet. Double click on the server in servers location. Choose "Use tomcat installation". Modify "Deploy path" to the tomcat deploy directory (Ex: c:\server\Tomcat 7.0.14\webapps). Extend "Publishing section". Check "Automatically publish after a build event". Save and close. From the eclipse menu check "Project -> Build automatically". From the servers view , right click on your server , "Add and remove" , publish you project.

查看更多
一个人的天荒地老
4楼-- · 2019-01-01 06:47

Simplest, quickest: set Eclipse up to generate a WAR file when you build; as a post-build step, copy that WAR file into your tomcat webapps directory. Tomcat will recognize the change and refresh the site with no deployment necessary. Note that this isn't perfect; users using that webapp may have a less than optimal experience, as Tomcat restarts the webapp "under" them; but this does fit your request.

查看更多
人气声优
5楼-- · 2019-01-01 06:48

can we use the below option? Double click on Server in eclipse -> Server Locations -> Use tomcat installation. It takes control of the tomcat installation. You dont need to restart the server for changes in java classes.

查看更多
墨雨无痕
6楼-- · 2019-01-01 06:49

This may not be the best way, but it works for me.

  • $tomcat/conf/Catalina/localhost/.xml
  • $contextPath/webapp/web/WEB-INF/lib/*.jar
  • $contextPath/webapp/web/
  • $eclispeWorkbench/project-servlet/src/
  • $eclispeWorkbench/project-servlet/servlet.jardesc (should export jar to lib dir in $contextPath)
  • $eclipseWorkbench/project-jsp/

I use an rsync command to sync up changes from my jsp project to the $contextPath.

Use remote debugging in Eclipse for Tomcat which will allow limited hot-swapping of code. If you change static fields or add methods, you will need to export the jar and restart the context.

查看更多
梦寄多情
7楼-- · 2019-01-01 06:50

There are two options.

First, Eclipse lets you do this, with a slight change of configuration (see also this detailed post)

  • add Tomcat to the server list
  • make the project "Dynamic web project" (Either through the creation wizard or through the facets section in the settings)
  • add the project to tomcat, and configure its "Deployment assembly"
  • double click tomcat from the list to open the configurations
  • Change "Publishing" to "Never publish automatically" (this means the server won't get restarted when you hit ctrl+s)
  • start tomcat in debug mode

This will still reflect code changes but won't restart the server.

Second, I've used the FileSync plugin for a long time:

  • configure the plugin to send all classes from the bin director to WEB-INF/classes of your tomcat installation (this is almost the same as configuring the deployment assembly)
  • configure all other resources to go to their respective locations
  • optionally, externalize all absolute paths from the filesync location settings to a single variable, and configure that variable in eclipse (thus you will be able to commit the filesync settings as well, if all members are using eclipse)
  • add Tomcat to the Servers list in eclipse, configure the "Server locations" option to be "Use tomcat installation" (the screen opens when you double-click tomcat from the servers list)
  • start tomcat in debug mode

It works perfectly for me that way. Every non-structural change is reflected immediately, without redeploy.

Update:
You can read more about the methods for hot-deploying here.
I also created a project that easily syncs the workspace with the servlet container.

查看更多
登录 后发表回答