可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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
回答1:
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.
回答2:
Simply let eclipse write the class files directly to the $TOMCAT/webapps/MyWebApp/WEB_INF/classes directory. Then, configure apache-tomcat to check if the class files have been updated, and reload them if they have.
To configure tomcat to auto-reload a class when it changes, you need to
edit $TOMCAT/conf/context.xml
and set :
<Context reloadable=\"true\">
You may also have to edit and reload your webapps/$YourWebApp/web.xml
file and include :
<web-app reloadable=\"true\">
I can\'t remember if both changes are needed but that\'s how I configured
my tomcat-6.0.18 to auto-reload.
回答3:
Disclaimer: I\'m just a happy customer, I don\'t work for Zero Turnaround and I\'m not in any way affiliated with them.
Check out JRebel - it allows you to code without web application restarts. It basically works by instrumenting your classes and adapting their changes. It handles many more cases than hot deploy, including:
- Adding/removing methods
- Adding/removing constructors
- Changing interfaces
- Adding/removing implemented interfaces
It\'s commercial, ( pricing details, $550/year as of June 2018 ) , and it has a lots of plugins for third party frameworks, including:
You get a free trial quite painlessly - I suggest you give it a shot.
回答4:
Change your workspace in Eclipse to \\tomcat\\webapps
Since it is just for your work, this should work fine. Whatever changes you make in Eclipse is in the same directory tomcat looks for applications to deploy
回答5:
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.
回答6:
Why not use an integrated tomcat server from with in eclipse if this is just for development? You can configure servers under window->preferences. Once it\'s configured if you have a jsp called page.jsp you can right click it and select run on server. Under preferences->general->Web browser you can chose weather to use the built in browser or an external one. Make some changes to your jsp, save, and refresh your page from the browser. The changes will be automatically reflected once you save and refresh your browser.
回答7:
What works for me here is:
context.xml like this:
<Context path=\"/myapp\" docBase=\"myapp\" debug=\"5\"
reloadable=\"false\" antiResourceLocking=\"false\" antiJARLocking=\"true\">
<!-- this because i´m using Spring 3.1 with Tomcat -->
<Loader loaderClass=\"org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader\" />
</Context>
Then, on Servers tab in Eclipse, on \"Modules\" tab, I disabled the \"Auto Reload\" to all the modules being deployed.
Also let the default config to let the auto publishing.
And is using Maven with WTP, don´t forget to leave the contents of src/main/resources in, because Eclipse insists to exclude the contents of this folder of the final build.
Only with all this I got full (VM) classes hot-deploy with resources hot-deploy!!!
回答8:
In your development environment, just point your Tomcat server to look for JSPs in whatever directory you\'re developing them in. As soon as you save the file, you\'ll be able to see the changes then.
回答9:
Are you open to using Jetty for development purposes?
If so, it\'s pretty simple to use with Maven - just run mvn jetty:run
回答10:
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.
回答11:
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.
回答12:
I\'ve found a simplest way: use of symbolic links: I think this is the fastest way because there is no synchronization at all: tomcat directory and your project directory will be the same directory all the time.
Tomcat will periodically detect the changes and redeploy your application.
There is also a way to debug your application, so I humbly think is a good solution.
I\'ve documented my solution here, for anyone interested.
回答13:
In case, you\'re in hurry:
- check \"never publish automatically\" in tomcat(other container) in eclipse.
- start tomcat(other container) in debug mode.
voila! :)
回答14:
I\'ve managed to get this working on my development environment using the Spring Loaded JVM agent. While I do develop Spring web applications, that project\'s description does mention that it is
usable on any bytecode that may run on a JVM
Using the following setup, I was able to get changes to publish automatically to an attached Tomcat instance (the usual Eclipse WTP method). I\'m using Spring Tool Suite 3.7.3 based off Eclipse Mars.2 (4.5.2).
- Download the latest release JAR of Spring Loaded from their Github project. This has been tested with springloaded-1.2.5.RELEASE.jar.
- Setup a Tomcat Server in Eclipse as normal (tested with Tomcat 8.0.30)
- Open the Tomcat Server\'s configuration page in Eclipse (double-click on the server instance within the \"Servers\" tab).
- In the \"Server Options\" section, uncheck \"Modules auto reload by default\".
- Note: If you have web modules added to the server already, you may need to disable \"Auto Reload\" on them individually via the \"Modules\" tab (at bottom of configuration page window).
- In the \"General Information\" section, click \"Open launch configuration\"
- In the \"Arguments\" tab, add the following to the end of the \"VM arguments\":
-javaagent:/path/to/downloaded/springloaded-1.2.5.RELEASE.jar -noverify
- To enable JARs to be watched in addition to project\'s
.class
files, configure the -Dspringloaded=watchJars=
VM argument per this issue\'s comments.
Start the server and publish Dynamic Web Application projects to it as usual. Again, I was able to test this with Spring web applications. For example, modifying code, adding/subtracting methods, etc. in @Controller classes were applied nearly instantly after I save the file and Eclipse builds and publish the changed class. Lastly, the FAQ section of the Spring Loaded project did mention a few cases where things won\'t reload, so those would require a restart of the server/application. But those exceptions are much less frequent.
One more note: This does NOT work with the embedded Pivotal tc Server or VMware vFabric tc Server that comes with STS. For those servers, there is a \"Enable Java Agent-based reloading (experimental)\" option, but that uses the older 1.2.0 release of Spring Loaded, which did not work for me.
回答15:
In Eclipse, click on the Project in the top menu and make sure “Build Automatically” is selected. This fixed my problem. I was running Eclipse with Tomcat using my workspace metadata. I was also running Maven in a Dynamic Web Module project. To verify, add your application to Tomcat. Start Tomcat from within Eclipse. Make sure your application is deployed and running. Open the Console tab in Eclipse. Make a change in your application. After a couple of seconds you should see your change getting automatically built and deployed to Tomcat.
回答16:
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.