Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
325 views
in Technique[技术] by (71.8m points)

IntelliJ and Tomcat....changed files are not automatically recognized by Tomcat

I am running Intellij Ultimate with Tomcat and deploy a war. Everything deploys fine to the webapp directory of tomcat.

When I change a file like an xhtml file, is there a way for tomcat to automatically pick up that change? As of right now I need to copy the file from Intellij and copy it to the directory of where it lives in the tomcat web app directory. I know there are certain files that will need a recompile, but xhtmls are not one of them.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This cannot be done if you deploy a war with IntelliJ IDEA. However, it can be if you deploy an exploded war. In IDEA:

  1. open your Tomcat Run/Debug configuration (Run > Edit Configurations)
  2. Go to the "Deployment" tab
  3. In the "Deploy at Server Startup" section, remove (if present) the artifact my-webapp-name:war
  4. Click the add icon, select 'artifact' and then select my-webapp-name:war exploded
  5. Click OK (on the "Select Artifacts to Deploy" dialog)
  6. Still in the Run/Debug Configuration Window, select the "Server" tab
  7. In the middle of that tab, change the "On frame Deactivation" setting to either "Update resources" or "Update Classes and Resources"
    • Update resources: All changed resources (that is, all application components other than the classes) will be updated.
    • Update classes and resources: All changed resources will be updated; changed classes will be recompiled. Note that whether the actual classes will be updated depends on the capabilities web server. If I recall, Tomcat will reload html/xhtml and jsp files, but not Servlets or classes that JSPs or Servlets use. You need to modified Tomcat to use a dynamic classloader for that.
  8. You can also set the "On 'update' " action to the one selected above as well.
    • This determined what happens when you hit the Update Update icon icon (or Ctrl+F10) in the Run window.
    • the "Show dialog" determines if IDEA prompts you each time you hit the update icon
  9. Click OK.

Now anytime you make a change, IDEA will redeploy the changed file(s) when IDEA's frame is deactivated (i.e. loses focus). It does take a second or two, You'll see it in the lower status bar in IDEA. Obviously. you'll still need to refresh your web browser so it fetches the new file (unless of course if the page has an auto refresh of ajax like fetch).

A good combination with Tomcat is to set "On frame deactivation" to "Update Resources" and the "On 'update' action to either "Redeploy" or "Restart Server". That allows static pages to be quickly updated via frame deactivation, and class updated via the 'update' action.

A company named ZeroTurnaround sells JRebel which is a dynamic classloader solution. They also have a five part series on the subject that's very good.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...