11

I have a Spring Web application and when I debug with IDEA's debbuger in Tomcat and redeploy the project after some changes, the changes are not deployed and debugger "sees" the old code (stepping through wrong or empty lines). Only thing that helps is to run maven clean install and then start the Tomcat again.

I tried clearing IDEA caches but it didn't help.

Hotswap also doesn't work, although I have correct options selected in settings, but I can live with that.

Note that I use redeploy not hotswap, so the whole application is started again, it should reload all classes but it doesn't. Only after maven build it works.

Note 2: I think it work ok one month ago, but no changes I can think of could do this (project- or IDEA-wise)

EDIT: So hotswap is now working OK (magically, I didn't do anything). But when I make larger modifications (eg. method signature change, etc), they are not picked up during REDEPLOY to the server. So I neeed to run maven clean install and start the server again to see the changes and for hotswap to work properly after method body modifications on this new code. Any idea why?

redhead
  • 1,264
  • 1
  • 17
  • 32
  • Please see the answer to [IntelliJ and Tomcat…changed files are not automatically recognized by Tomcat](http://stackoverflow.com/questions/19596779/intellij-and-tomcat-changed-files-are-not-automatically-recognized-by-tomcat/19609115) – Javaru Jan 09 '15 at 13:59
  • I've seen this this answer, I have exactly the same settings. – redhead Jan 09 '15 at 14:08
  • Can you post a screenshot of your run/debug configuration? Also, what versions of things are you using? i.e. IntelliJ IDEA, Tomcat, Java, Spring. I just retried this on a simple webapp project and all works as expected. – Javaru Jan 09 '15 at 14:39

4 Answers4

6

You need to check your run configurations of tomcat, in "Before launch" there should be Make and Build artifact steps, also be sure that all you changed classes are really compiling during redeploy - this is the place I would start from.

Also I don't get why you use redeploy instead of hot-swap? Redeploy is usually same time-consuming as restart server, but hot-swap is nearly instant. Though it allows only to change method bodies and constants, usually it's much prefferable then redeploy in development. Personally I'm using JRebel which is free for non-commercial projects now and restart server very rare.

EDIT: I don't know why your classes are old even after redeploy, but the reason is 99% that they do not compile after changes into exploded folder. Doing maven clean install after each code change is too much (IDE compilation should be enough).

What I can suggest you is not to redeploy but to restart server after big changes. So that IDE perform Make, Build artifact and Deploy artifact tasks.

davidluckystar
  • 928
  • 5
  • 15
  • In "Before launch" I have 'Make' as well as 'Buld exploded war artifact'. As I said, hotswap also doesn't work, it says that it's compiling classes and then it shows 'all files up to date' but debugger still misses the changes (even though they are in method body). – redhead Jan 09 '15 at 11:45
  • And what do you have in section Debugger -> HotSwap in Settings? There should be 3 radio buttons, you should either set 'Reload classes after compilation' to "Always" or "Ask". Also just to be clear: you need to run tomcat in debug mode, or connect to it with remote debugger. – davidluckystar Jan 09 '15 at 12:28
  • I do have "Always". Even if hotswap didn't work, redeploy should. Also I can debug the code just fine, but the changes need to go through maven build for the debugger to see them. I am using local tomcat, why do I need to use remote? One more thing: it did work one month ago just fine. – redhead Jan 09 '15 at 12:54
1

In addition to david.lucky hints, make sure that on your Tomcat configuration in the deployment section you're using an exploded artifact

Master Slave
  • 27,771
  • 4
  • 57
  • 55
0

I had exactly the same problem! I've spent hours in solving this issue.

I don't know why, but the solution for me was that (I'm working on MacOS High Sierra):

  • First, I had some of my tutorial projects, I was working on, on my Desktop in a folder /Desktop/tutorial/... These project were working fine. I could redeploy and Tomcat was recognizing the changes in my java files.

  • Then I started some new, own projects, and I placed them in my home directory, something like /Users/myHomeDirectory/WebApps/. I could build and run these objects, but when I made changes, I had the same exact problem, that Tomcat was not recognizing the result. Only thing that helped out, when I clicked Maven-Button "Reimport all Maven Projects".

  • I tried really lots of different things. Nothing worked.

  • Then I thought, maybe, theres something wrong with my project. So I took one of my projects from Desktop and copied them into my home directory. But suddenly, I had again the same problem.

  • So here's my solution: I created a new project on Desktop again. And I don't know why, but now it's working fine. I really have no clue why. And believe me, I did not change any settings. I did exactly the same!


And regarding the life reload without redeploying. This works really fine for me (without any plugins like JREbel):
  • Go Run –> Edit Configurations –> “Deployment” tab, clicks + icon –> select an “exploded artifact”
  • Select “Server” tab, update the following options :

    1. On ‘Update’ action -> Update classes and resources
    2. On frame deactivation -> Update classes and resources
  • Run web application in Debug mode. Try to modify some codes or resources (Java files, ...), the modified classes and resources will be reloaded automatically.

toniweser
  • 55
  • 8
0

This has been happening me for some time now Ultimate Edition after switching from eclipse to Intellij a few months ago. Standard tomcat config and debug settings mentioned above used.

Intellij will show green popup after nothing to reload or reloaded one class. Yet the debuggers bytecode is not the same reloaded/updated code.

You can force a recompile which will work for small changes ctr shift F9. Other than that a clean install seems to work for annotation, method definition changes etc. If you try a recompile the debugger will fail the server.

So the answer is ctrl shift F9 on the file you change

Nanotron
  • 554
  • 5
  • 16