Eclipse keeps running my old web application - java

OMG - what is going on with Eclipse (3.3 Europa) - has anyone come accross this problem (bearing in mind I have been messing about with uninstalling different Tomat containers and installing others - but anyway thats another story)
When I change a line of code or remove a class within my project - when I come to debug - it actually goes to a line that is commented out and runs that line regardless!!!! e.g.
//System.out.println("you should not be able to read this!");
UPDATE: This can be solved by setting Project -> Build Automatically (see answer below).
REMAINING PROBLEM:
Eclipse is not keeping my hot deploy folder current with the latest changes to my project:
I found out to my horror that some old remenants of my project are 'hanging around' in the folder that I think Eclipse uses for hot deploys or something
C:\myJavaCode.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\myWebApp
basically it is not actually copying accross any changes made in the classes of my working dir!?!??
...anyway - in order to keep my project up to date - I have to modify this folder too - TOTALLY UNACCEPTABLE - as you can't develop in this way - it would take you eons! Anyway, if anyone can help explain to me what stupid thing I have done to get me in this mess and how I can get out of this mess - I would really appreciate it.

Have a look at:
Windows>Preferences>Server>Launching...
and:
Project>Build Automatically
maybe you accidentally disabled the auto-deploy features.

I had a similar problem, only without the added complexities of a web app. I'm just running a JUnit test and it's running the old code. I went into Configure Build Path, on the bottom of the Source tab, and looked at Default Output Folder, which said myproject/bin. The Package Explorer doesn't even show a bin folder, but when looking at the file system there's a bin folder there. I deleted the bin folder, refreshed the package explorer tree, and it worked. This behavior was in Helios and occurred with AND without Build Automatically selected...looks like a bug to me.
Dave

A super-silly question: Does all your webproject and related projects compile correctly?
Also check your output folder for classes (Project Properties -> Java Build Path -> Source Tab) then go to your filesystem and check permissions and modification dates.
Hope this will help you.

Probably the easiest way to get past this is to define a new server.
Right-click in the Servers window and select New, or when you do 'Run On Server' select Manually define a new server. You can have multiple servers defined using the same Tomcat runtime (they'll all have separate configs and deployment directories defined by -Dcatalina.base=...), but don't run them at the same time unless you change the ports they're listening on.
The new server will use a path like
<<yourEclipseWorkspace>>\.metadata\.plugins\org.eclipse.wst.server.core\tmp1
for the Tomcat conf and webapps directory.
Try running on this server. If it works, you can compare settings with the old one,
maybe try deleting the app from it and re-deploying, and figure out what you might have done to cause the problem. Or just delete the original server config.
As far as your second problem, I'm not sure. I'd try a new server config first, get it working, stop the server, do a 'Clean' on your project, delete anything in the tmp1\work\Catalina directory, and restart the server (you could remove and add your project to the server again too to be really clean).
Check the console messages too to make sure there were no errors related to this.

Related

IntelliJ IDEA doesn't redeploy changes

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?
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.
In addition to david.lucky hints, make sure that on your Tomcat configuration in the deployment section you're using an exploded artifact
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 :
On ‘Update’ action -> Update classes and resources
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.
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

Eclipse version control - problems with project no longer showing in workspace

I'm trying to figure out which files to check in to version control when using Eclipse for Android development. I have a workspace with a single project. I found this which suggested that the .metadata folder did not need to be controlled (minus the comment there about launch params, however I don't mind re-picking those again on a different machine).
If I remove the .metadata folder then open Eclipse the project is no longer shown. I searched for posts on this symptom and they suggest re-importing the project. This solution doesn't make sense here, I'm trying to check in whatever is needed so another developer can open the workspace and see the project and work on it. Having them move the project then re-import it would be a bit messy.
So which files should I be version controlling so that someone else can get the latest and be able to open the project without controlling a bunch of user specific preferences?
I have had similar experience using Eclipse for version control, and decided to quit using it because it is very annoying and buggy. Now, for git, I use SourceTree, which I prefer over eclipse version control. I think you should version control the source code folders, along with configurations, and other files you program needs to function, but never the executable files. If the other person is using Eclipse, for easiness, it is good idea to include the .classpath configuration file. If not, then the other person would need to clone the repository and make the required changes so that it works with his/her IDE.
I think I've settled on the following approach. This seems to work well so far and avoids some of the headaches mentioned in my original question.
1) each developer creates an Eclipse workspace on their machine somewhere, outside of version control; only the project directory is checked into version control - the workspace is completely uncontrolled
2) developers checkout the project directory from version control (in a different directory structure than where the workspace was created) and then use File >> Import, but they leave the "copy into workspace" unchecked.
So with the above, you can checkout from version control and work with the files right where they were checked out. There's no need to move them out then import them back in. When you import with the copy option unchecked, the workspace (which itself is not controlled) is just referencing the files where they're at on disk.
The only minor downside is that any workspace stuff has to be setup individually. Other articles mention controlling the launch params, but so far this hasn't been an issue - pretty easy to pick that once the first time you launch.
So anyway, hopefully this helps someone else :) This seems to be a reasonably smooth way to do it and avoids the issues we ran into initially.

Sudden weird errors on a project

Today I came to work, happy. But when I opened my Eclipse, I saw that one of my projects has errors.It's weird because it shows that it has errors only in the window bar, and not in the Navigator. I don't have any Java errors, this is a valid project that was fine all the time:
Some of the errors on the error log of Eclipse:
JavaBuilder handling ImageBuilderInternalException while building: SP_Procedure
Cannot connect to VM
File <SomeFile> has been skipped, problem while reading ('Resource is out of sync with the file system')
Unhandled event loop exception
Internal error
When I run an application from this project, I get a warning message but when I proceed, it works fine, but still. It's very disturbing and I'm not sure if it's harmless.
I tried to:
Restart Eclipse
Restart my machine
Clean projects and recompiling them.
Refresh projects
Pray
Nothing helped. What could be the problem? (I'm using Indigo Service Release 2)
The following nuclear option has desperation written all over it. But I have been where the OP has been with the Juno version of Eclipse.
Run a "Synchronize with Repository" and save all of your local updates to a different directory.
Delete the project. (Check the box to delete the contents on disk. Scary step, but that's OK, because you saved it in a different directory in the previous step, right?)
Read in a fresh project from the repository. It builds happily at this point.
Integrate your local updates.
Keep on praying.
Looks that one unused JAR was deleted, but for some reason, I didn't get errors in any file, even in the files that imports this JAR! So what I did was restoring this JAR, delete unused imports and deleted the JAR again.
I've found this error after two days of navigating on this project on each file.. This is weird that Eclipse didn't recognize that1 this is an error, and throw many unrelated errors such as:
Cannot connect to VM
File has been skipped, problem while reading ('Resource is out of sync with the file system')
Unhandled event loop exception
Is this a bug in Eclipse? (All errors and warnings are enabled!)
1 As seen in the image in the question..
A class from the list of imports for the file seems to have moved out or the jar file containing the class is missing.
Expand the imports section and check if you find some classes that are missing but have been imported.
Though it is a pain, sometimes the easiest solution is to back up all your projects (either in a repository or somewhere else on your computer) then uninstall and reinstall eclipse. No it's not fun, but it should reset eclipse so everything works again. The downfall though is that you have to reconfigure eclipse to any special settings you had/reinatall any extra functionality currently installed (eg. android add-on) and reconnect to any repositories you have. While punting isn't fun, it can be effective... I hope you don't have to resort to this though.
I have went through that problem a lot of times, and tried everything you tried. Rebuild, recompile, refresh, remove and add JDK, remove and reinstall Eclipse... nothing worked
The only thing I concluded is that the workspace metadata was corrupted.
What I did (every time it happened) was
Create an empty workspace
Import -> existing projects into worskpace
Mark the "copy projects" (else it will only link them)
Wait for the copy, and start working with the new workspace
If you work with SCM systems (Git, SVN, etc), making a full checkout will do the trick too, but the worskpace import will let you retrieve those changes you didn't get to commit (if any).
It's a little painful if you have somethings already set (like JDK names, servers, etc), but then I realized it was faster than keep searching how to fix the workspace
Regards!
PS : I've been working with Kepler lately, and everything works fine till now
Click Window -> Show View -> Other -> General -> Problems
This view will show you what is wrong.
Did you, by any chance, update your virtual machine outside of Eclipse? I can't help but feel that we're both missing a finer detail here. I just keep seeing "cannot connect to VM" and thinking that it's a major clue.
Have you tried running anything from the terminal? Does it work there?
If so, do you know where your current edition of Java is located? Is Eclipse looking somewhere else?
Is this exclusive to one project? Do you use any additional libraries to the JDK?
Maybe try this for Resource is out of sync with the file system error:
Right click project in Eclipse Package Explorer
Close Project.
Right click project in Eclipse Package Explorer
Open Project.
Other things not mentioned:
project properties > java build path, see if any of those tabs got changed, local file got moved? read/write permissions on some file you are linking to?
project properties > java compiler, see if workplace settings have changed? maybe under errors/warnings, you can systematically set them to 'ignore' until the error goes away to determine what type of error it is?
maybe update some of the eclipse plugins?
I saw something like this happening for a number of reasons. Mainly because of validation in files other Java source code. See if you are validating XML for instance.
Right click your project and chose Properties (Alt+Enter) and Validation to see the related configuration.
As for the danger, I lived with those marks for ages and nothing wrong ever happened.

eclipse/tomcat: deploy doesn't work any more (ClassNotFoundException)

I'm running Eclipse Helios Service Release 1, with Tomcat 7.0.12 in Linux Ubuntu Natty Narwhal.
I've been happily hot re-deploying my webapp until it stopped working for apparently no reason. The following exception is displayed:
SEVERE: Allocate exception for servlet Index
java.lang.ClassNotFoundException: obliquid.servlet.Index
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
In Servers tab I've "Tomcat v7.0 Server at localhost [Started,Synchronized]
My project appears as a child of Tomcat v7.0 Server
In Properties, Java Build Path, Source I've Project/src Source folder
In Properties, Web Deployment Assembly, I've the following mappings: /WebContent -> /, /src -> /WEB-INF/classes, /test -> /build/classes
My src directory contains a Servlet in obliquid/servlet/Index.java
I tried already to click on Clean Module Work Directory... and Publish
I tried to stop and start the Server from within Eclipse Servers tab
What else should I check? Thank you.
UPDATE Despite now I'm working with the new project, I came back to check the old one, and mysteriously now it's working. I think I won't be able to find what has happened.
However today with the new project, I had 404 errors with no apparent reason and I found out that right clicking on the Tomcat server and selecting "Clean..." can be useful. Maybe it could have helped.
Selecting "Clean..." says: "Clean will discard all publish state and republish from scratch. Are you sure you want to clean all published resources?". Selecting yes, I solved the problem
UPDATE 2 It happened again on the new project. 404 errors, this time they don't go away.
Stop -> Clean... -> Start (404)
Stop -> Clean Tomcat Work Directory... -> Start (404)
Stop -> Clean Tomcat Work Directory... -> Clean... -> Start (404)
Stop -> Remove on the application -> Clean... -> Run As -> Run on Server -> (404)
Exit Eclipse, Start Eclipse
Start the server -> (404)
UPDATE 3 It turned out that this time I just didn't notice an exception caused by a listener-class during startup. After solving the problem, it worked. Guess I should stop working at 3 AM.
While on Tomcat 6 and Eclipse Ganymede I found out the following chain to work like charm:
1 stop server
2 project -> clean
3 project build (I had automatic build disabled)
4 delete server
5 delete Servers folder
6 restart Eclipse
7 create new server, add project and start :)
takes some time but worked like charm. My problem was a irritating Listener start problem, but this seems to be something similar: a property at tomcat. Btw: nowadays I am also a big Glassfish fan.
I found that this procedure is useful:
Click on Servers tab and Stop the server in use if it's running
Right click on the server again and select Clean...
Right click again and select Clean Tomcat Work Directory...
Hopefully the ClassNotFoundException should be gone now.
Another time I had a problem with a class launched at server startup, an exception in a listener class (ServletContextListener). When a ServletContextListener raises an exception during startup the application deployment is aborted, hence the 404 errors. In that case fixing the problem that caused the exception, made the application working again.
EDIT: This shorter procedure worked for me most of the times, but today didn't work and I had to follow Mico's extended procedure. My suggestion is, if you have a similar problem, first try this shorter procedure. If the problem persists, try with Mico's.
I'd recommend that you stop and start the Tomcat server again. Hot deploy does not work forever; there are some issues that will cause you to have to restart after a few redeploys.
I wonder when I see the accepted answer with +25 is it really accurate?
First if you are going to delete the server then whats the point in cleaning it? It will take your time unnecessarily and nothing useful will you gain.
So i will say just 5, 6, 7 steps should do the magic
5 delete Servers folder
6 restart Eclipse
7 create new server, add project and start
This could be something I learned on con-fess 2011. For me this sounds like a classloader problem.
The theory behind:
Java does not only use the type of the class but also the classloader which loaded it to identify the type of an instance. This means a simle operation could fail, e.g.
ClassA a1 = new a1;
ClassA a2 = SomeOtherClass.giveMeInstanceOfA();
a1 = a2;
This example would fail if SomeOtherClass uses a different classloader because Java would say that they are not the same.
The speaker also mentioned that some servers use per default about 45 different classloaders.
What does this mean in practice:
You deploy your webapp to the server, everything runs fine. The server caches the classes and everything he needs to load them somewhere. Now you make a hot deploymen and the server may loads new classes with a new (or different) classloader. This is the point where it starts to become dangerous because from now on you have two different classes in the memory which should be the same. Simple operations like casts (ClassA a = (ClassA) new ClassA()) fail, new Methods within the class are not found (because the server takes a cached version without this method),....
This is the point where I restart the server, clean the working directory (to get rid of the cached versions) and start thinking about hot deployment as critical thing.
If it is possible to try Mikkos procedere and this solves the problem this explanation could help you understand why.
I know this does not solve your problem but could give you some hints what maybe could have happened.
Speaking of hot deployment of Tomcat, you would indeed experience various problems, the least of which is memory leak, which is why you would have to restart the application. I would recommend to try JRebel for fast turnaround of "make and save any changes and then refresh the browser and see the changes immediately". You can find the JRebel hands-on lab, which shows how to use it with Tomcat and Eclipse. http://www.javapassion.com/rebels/jrebel_basics/
I have gained some new experience on programming and I am not anymore starving on Eclipse + Tomcat combination. Several ways here can help you out of the need of the usage of that combination:
First of all, don't use them together!
You can use other available IDEs, e.g. IntellijIdea (that is not free, but is worth of investing) has an property that when you debug a Java code, you can change code on fly and compile the Java files one by one and then it suggests if you'll want to have it updated on server. No restart needed almost never (of course it sometimes gets lost, but mainly it works).
Use standalone tomcat server, not the one inside Eclipse / your IDE. That first trick works only when you debug external server, nothing inside IDE. There comes the second tip: if you happen to change only jsp or html content, those files can be copied to the right place inside tomcat's webapp folder manually with unix cp or windows copy command and if you happen to develop files in same foulder long time, you can copy the folder content (e.g. myFolder/*.jsp) as many times as you wish and no restart is needed at all. The changes come visible when you touch or edit&save the web.xml file inside the webapps folder and then after that with refreshing the visible page on browser. Probably hard refresh with CTRL+F5 is the best way.
Thanks to #Verdan about his comment, otherwise I wouldn't have came back to answer again.
I was able to solve this by disabling the maven nature (right click on project >> maven >> disable maven nature). Then re-enabling it (right click on project >> configure >> convert to maven project). I had tried all of the other tips and tricks above, but this is the one that finally worked.
I was running into the same problem - tried all of the above, Eclipse always freezed when i tried to start the server, even after i deleted all the server configs and created a new one with a freshly downloaded tomcat instance. Anyways, problem wasnt solved until i moved to a new workspace, reimported the projects and created a new server. Seems like an Eclipse bug to me...So in case nothing else works, this is the way to go...
I'm currently struggling with the same problem, but nothing mentioned here does not help me. Anyway, I found out that if I:
stop server in eclipse
run tomcat elsewhere (in my case the xamp distribution)
stop currently running tomcat
start tomcat in eclipse
everything works just fine, of course until I change something in code and try to test it again.

netbeans "Please wait - classpath scanning in progress..."

When i try to compile netbeans projects i get this message/error :
"Please wait - classpath scanning in progress..."
and nothing happens , its like you have have to wait for enternity to conmpile "hello world"...
Now the first thing is that we have moved to a new office building, but the laptop is the same. It's a very secure enviroment with a lot of "security", can't connect anywhere almost.
Also i have changed the user dir in netbeans.conf to save my data in c:\Program Files\User
Any ideas how to fix this?
alrady tried reinstalling netbeans, changing save location between standart and newone...
Just some ideas to find the problem
Look at the CPU - is netbeans busy (100% on one core) or blocking (95% idle)?
Standard, ant or maven build? Where are your libraries and do you use absolute or relative paths?
Start with a simple "hello world" project (no dependencies), then add one lib (log4j or something similiar), located in a project folder and - if this works - move that lib to other locations (choose locations similiar to the libs on the real classpath)
There is a chance, that you don't have access rights to the folders/shares that contain your libraries. Or, as you mentioned security, that some virus scanner blocks access to some highly dangerous libs...
I deleted all the files under the .netbeans/7.0/modules directory. Although I lost some configurations of the IDE, it started to work pretty fine.
http://wiki.netbeans.org/FaqWhatIsUserdir
I followed Andreas-d advise... after disabling the antivirus and restarting netbeans everything is back to normal.
This seems interesting issue as per you have specified ! Somewhere, the netbeans documentation writes that the issue has already been resolved. However, for your information please have a look on : Scanning Project Classpaths takes too long
This link may or may not be helpful to you. But, the discussion may provide chance to resolve it.
Thank you.
In my case, when adding JavaFX libraries in my project: properties >> libraries >> Compiler Tab >> Classpath option, I have accidentally added my root user (C:\users\paulo) along with the JavaFX jar files. That was making NetBeans to scan basically my whole harddisk. The solution was very simple: just to go back there in properties >> libraries >> Compiler Tab >> Classpath option >> Edit button and deleted that "c:\users\paulo" and almost immediately the scanning processes went away.

Categories

Resources