14

I use Eclipse Indigo (EE) to build applications in Java framework Vaadin, using Tomcat 7.0 server. After changes in code I wont see result in a browser, so I need to click option "Clean Tomcat Work Directory.." and wait until Tomcat stop and start a server.

Otherwise, when I refresh app page, I don't see any changes. Even when I restart server (and when eclipse automatically restart it when I save changes), without cleaning tomcat directory.

Option "Automatically publish when resources change" is enabled.

Is any faster way to do that? or can I automate that process?

mokrzu
  • 203
  • 1
  • 3
  • 9
  • Do you really need to develop in Tomcat? It's easier to develop in Jetty, it's much more lightweight and automatically restarts when your code changes (optionally, of course). – cthulhu Jul 24 '11 at 17:57
  • you can have hot deploy follow the steps here http://stackoverflow.com/q/998737/106261 – NimChimpsky Jul 31 '12 at 10:09

6 Answers6

6

Additionally to the answer of Kowser, it is possible do hot code changes when running tomcat in debug mode.

Otherwise you could investigate in JRebel

Omnaest
  • 3,096
  • 1
  • 19
  • 18
  • JRebel doesn´t even require time to investigate, if your app uses a standard arquitecture layout (as I suppose yours do) you will get your changes in code (modifying methods, creating classes, etc) inmediately refreshed. But even with this, I would suggest you to go for unit testing to test your code, and using JRebel when modifying controllers only. – Jaime Hablutzel Jul 24 '11 at 20:34
4

In your "Modules" tab of your Tomcat, you hace to clic on 'Edit' and uncheck the 'Auto reloading enables' option.

With that, several changes won't need a restart (as long as you start your server in debug mode).

Gayolomao
  • 586
  • 4
  • 15
  • This problem has been annoying us since our move to Tomcat 8. Previously I had only seen "Modules auto reload by default" on the "Overview" tab. Thanks - this saved us a lot of time! – user2274508 Jun 09 '16 at 13:52
0

I know this has been asked and answered very long ago. But use this info if it is helpful to anyone of you. I use Eclipse Kepler and configured Tomcat 7 server inside eclipse. I don't have to do any other configuration but to just uncheck Update context paths check box. That is all. Leave other setting as default.

In this way, changes to the resources files (xhtml pages, css files etc.) as well as the java source code files show up in the browser. Only for class files the web application would be redeployed (no server restart auto as well as manual required).

Location of Update context paths: Double click on the tomcat server under Server tab. Under Publishing tab you would find this Update context paths check box.

Absolutely no other change needs to be done for the auto publishing. This works both in normal and debug mode of tomcat.

Screen shot from my eclipse below:

enter image description here

PhantomReference
  • 718
  • 2
  • 14
  • 27
  • Unchecking that did't make any difference to me. I think this is a long outstanding bug and I don't think they care to fix it. – jotadepicas Jul 07 '17 at 00:41
0

If you setup your project to use ant for building and deploying, you can simply add Ant builder to your project Builders to run your ant build and deploy targets every time after you have saved a file. Then provided that tomcat is configured to support auto-deploy, this should achieve what you want, with two caveats:

  1. If your project takes more than a few seconds to build, building after every save is not practical.
  2. You may run out of memory for the tomcat instance if the same app is deployed to it repeatedly for a number of times. This can happen if tomcat is somehow unable to recover all the memory from undeployed resources.
prusswan
  • 6,853
  • 4
  • 40
  • 61
0

It might be possible. But your setup is a bit different from what I use. I am just using tomcat+eclipse to do Servlet development using Velocity and Torque.

The following works for me where changes are visible in the browser as soon as I save in eclipse.

I assume that you have a project directory such as

apache-tomcat-7.0.11/webapps/$YOU_PROJECT/WEB-INF/classes/

Create a symbolic link with ln -s from your eclipse project directory and to the classes directory in WEB-INF.

Then configure eclipse to write all .class files to this directory. (Done by right clicking on the project in Eclipse and choosing Properties and then Java build path.

In your $tomcat/conf/context.xml config file first tag should be:

<Context allowLinking="true" reloadable="true">

Also add the following as a child to if it is not already there.

<WatchedResource>WEB-INF/web.xml</WatchedResource>

That is what I have done, but I am not sure it works with your EE tools.

ps: This solution assumes that you are using linux/unix. I don't know if it works with windows. The major problem is that eclipse can't write class files outside the project directory (Which is why that symlink is required).

btw: Tomcat may(Depending on class loader, used .jar files and other complicated details) leak a lot of memory when automatic reload is enabled so you may want to increase the allowed memory(Mostly permgen) to prevent out of memmory exceptions from tomcat.

MTilsted
  • 5,425
  • 9
  • 44
  • 76
  • It might work in Windows 7 too. It depend on exactly how Eclipse handle windows Shortcuts. The only linux specific part of the solution is the way I put a symlink(Shortcut) from the eclips eproject directory to the tomcat directory. And this is only needed because eclipse for some insane reason can't write its class files outside the project directory. But if eclipse can handle Windows shortcuts then it might work in windows too. – MTilsted Jul 25 '11 at 05:30
-1

No, there is no other way.

You will notice immediate changes only while updating a JSP/HTML/etc.... Classes will not be loaded/refreshed automatically. It will be contradictory to change a loaded/instantiated class when server is live, isn't it? At least it should not be possible.

It's better to perform Unit Test while developing something. It can help you to reduce the amount of annoying server restarts.

MD Sayem Ahmed
  • 28,628
  • 27
  • 111
  • 178
Kowser
  • 8,123
  • 7
  • 40
  • 63
  • 12
    That's not true. JVMs have supported hot code replace for some time now, so certain changes can be applied to a running program in a JVM. This doesn't always work (if you local variables, method signatues, etc.), but works great for a lot of debugging. – g051051 Jul 24 '11 at 18:34
  • Yes, agreed about the debugging. Apart from that I am just told that there are some tools which allows swapping jars in production server. But I have not investigated whether it is possible or not. – Kowser Jul 24 '11 at 19:54
  • 1
    this is not true, you can have hot deploy follow the steps here http://stackoverflow.com/q/998737/106261 – NimChimpsky Jul 31 '12 at 10:10
  • @NimChimpsky Does your judgement include giving a down vote for not mentioning the "debugging feature"? It is acknowledged above, commented by one user also. Additionally you have the option to improve the answer, or add your own. I am not against you, but to me your act is rudeness. – Kowser Jul 31 '12 at 13:38
  • 3
    @Kowser the answer is wrong and misleading, it should not have been accepted. Hot deploy works on everything excepting changing method signatures, which require a reload. – NimChimpsky Jul 31 '12 at 13:54