Eclipse run old version of program - java

I have a problem while runing my application in eclipse. I make some edits like this:
String res = "newvalue";
System.out.println(res);
But when I run the application I still receive "oldvalue" in output. After this I tried to delete main() function - and I run application and I see "oldvalue" in output again.
Maybe it's some cache in JVM, or smth. else?
UPD:
It's 15:35 on my clock now. But in /bin folder I see .class files with 14:33 timestamp. I change source files (.java), press ctrl+f11 in eclipse and files in /bin folder are still 14:33 ...
UPD2:
After cleaning the project I receive the following problem:
The project was not built due to "Could not write file: D:\projects\NelderMead\bin\ru.". Fix the problem, then try refreshing this project and building it since it may be inconsistent
SOLUTION
The problem was that eclipse can't write file to the folder with spaces and UTF chars in it's name. So, I copy project to the new clean workspace and it runs without problems! Thx all for help detecting the problem!

You're executing an older class files, the reason could be
a compile error somewhere else (see problems view)
or your changed accidentally the source path so that the new source no longer gets compiled.
Try to clean the project and make sure the new classes are compiled to your output folder.
The JVM doesn't have a cache for class files.

First, make sure the file is saved (there is no asterisk next to the file name in the tab). Usually files are saved automatically, but you could choose not to save files and never ask by mistake, the first time Eclipse pops up this dialog.
Then see what's going on in the Problems view. You might see something like project cannot be built due to the following reason. It may be because of compilation errors in the dependent projects.

Related

How can I clean up my eclipse project after deleting a .java whose .class file still seems to be somewhere?

So, I deleted a couple of .java files from within eclipse because I didn't need them anymore. However for some reason another class still uses them and compiles without a problem. When I go to the declaration of the constructor of one of the deleted classes a .class file opens of that class even though I thought they got deleted by eclipse when I deleted their .java files.
I have tried to clean the project and I tried to find the .class file using the system file explorer in the folders that are listed in
project > properties > resource > linked resources. However I couldn't find them.
Now, since I deleted those files/classes there should be a compile time error wherever they are used but everything compiles without an error, even using the code that should've gotten deleted. A colleague that recently joined the project does receive compile time errors, since he doesn't have those class files. And I want to get them too, so I can fix the code where the classes were used. Of course he could show me the lines of code that are affected but if this happens again he would probably be affected as well as he would have the class files by then.
Try doing the following
Go to project > properties > Java Build path >Source
under that you can find Default Output Folder section, simply delete the classes folder under that location with in your project.
Try cleaning the project.
Or
Simply close the eclipse and reopen it again, sometime this would work for me.
Hope it resolves your problem
If you just deleted the sources, they binaries would still be there. So open the Navigator View and go to the project in question. Look for the bin directory and delete the appropriate class files. Otherwise, delete the project itself.
You should also ensure that no other programs depend on those class files.
I found the problem. Someone built a .jar file I didn't know of which contained a lot of old code.
I found it by right clicking the constructor and selecting
references>project

.class file isn't syncing with .java file when debugging

I might be using the wrong term when talking about "sync" but that's the best way to descrie it I think. I'm trying to debug a project that I've been working on for a couple of days now but for some reason the .java class and the .class file aren't syncing (.class file isn't updating to any of the changes that I make to the .java class that I'm editing). Let me start from the beginning I guess, when I do add break points to my .java file (sometimes the breakpoints are skipped) that I'm debugging and run the debugger when the breakpoint is reached the .class file is opened in instead of the .java file.
I searched around and found the solution to that with the help of some topics on here, which was "Edit source lookup". So the part about .class opening instead of .java file instead was solved. The main problem now is when I do edit the .java file with anything and run the debugger it completely ignores my changes. For example, if I implement a System.out.println("Test: 1") before a breakpoint or even after it's not printing to the console. Another example is if I comment out a line of code and run the debugger, the debugger still executes that line of code that I just commented out.
I searched for some solutions but they didn't help much. Some things I've tried were but did'n work:
Why isn't Eclipse updating the classes?
1.) Make sure the Build automatically is checked
2.) Cleaning the project
3.) Refreshing the project, F5
4.) Go to Wwindows->Preferences->General->Workspace and making sure the first 2 checkboxes are checked.
5.) Saving
6.) Restarting ecslipse
If anyone knows how to maybe solve my propblem I will be indebted to you. By the way I'm using java 1.7
What you describe indicates problems in you project definition.
Make sure that your project (main runnable class) specifies correct dependencies - that it does not specify dependencies on other jar files but includes dependencies from your related projects

Running .jar File Java 8

I've run .jar files before, but I've encountered a "different" situation, and I'm not sure what to do. I'd appreciate if someone could help me out.
Previously, I programmed with Java 6 and Eclipse Juno exported all my programs to runnable jar files. I'd get a .jar file that I could run by just double clicking on it. The files always looked something like this (note the jar file icon):
Recently, I wrote a program in Java 8 with Eclipse Luna (Release 4.4.0) and exported it to a runnable jar file, and I got something different (note the different file icon):
It no longer runs when I double click it. Instead, my computer uncompresses the jar, as it would a zip file. I tried running it from terminal. I cd'd to the directory and typed
java -jar graph3D.jar
I got the following error message:
Error: Unable to access jarfile graph3D.jar
After uncompressing the jar file, I found a folder named META-INF with the manifest file, MANIFEST.MF in it. It was the only file that seemed to resemble an executable file. Do I have to do something with that?
Could someone explain how I can run the second jar file graph3D.jar? Is it something new with Java 8, or something different about Eclipse Luna, or something else?
(Both programs run fine in Eclipse, by the way)
Thanks for your time and help.
Edit:
Below was the dialog box Eclipse displayed if anyone is interested.
Selecting "Use .jar;.zip" makes the filename "graph3D.jar;.jar;*.zip" .
Selecting "Use .zip" makes the filename "graph3D.jar;*.zip"
Selecting "Cancel" doesn't let you go forward.
You'd have to manually delete the extra file extension.
Somehow when you exported the file, the filters for the file dialog box (*.jar;*.zip) got attached to the filename, which is graph3D.jar;*.jar;*.zip, not graph3D.jar. Java can't find it because it doesn't have the name you supplied. Rename the file and pay close attention next time you export; either you fat-fingered something, or you're triggering a significant bug that needs fixing.
I recommend that you will access the build folder after you've built your project on the IDE under your project folder (in your workspace) and copy both the libraries folder and the .jar and post them wherever you want the program to be "installed", you'll then have an executable jar that should run smoothly without problems, just as I said don't forget the lib folder.
I think there is nothing new in Java 8 related with the running jar, I guess you need to check the the Eclipse export issues, it seems your classes are missing from your second jar file.

Eclipse crashed, works space now can't be opened, and importing the projects wont work either

Eclipse crashed, works space now can't be opened, and importing the projects wont work either. That about explains it all right there.
Creating a new workspace, I still cant import any of the projects. It acts like it is about to, but then nothing.
Any ideas? Not all of the projects are on svn.
Here are some of the errors i see in the crash reports
The file has been changed on disk, and it now contains invalid information. The project will not function properly until the description file is restored to a valid state.
Premature end of file.
does not exist
and the message that appeared before it all crashed and burned
java.lang.OutOfMemoryError: Java heap space
NEW INFO
every single file in every single on of my projects, now has a size of 0kb. all the files exist, but every .png, .jpg .class .xml is empty with a size of 0kb
try editing eclipse.ini file.
put put -Xms512m -Xmx1024m
then try to restart eclipse it should work!!
Can you install a second instance of Eclipse and point it at the workspace? I've done this with the ADT on my mac before.
I have had similar trouble with corrupted workspaces in the past. They don't load even in a fresh copy of Eclipse.
What has helped me is deleting/renaming file myWorkspace/.metadata/.plugins/org.eclipse.core.resources/.snap
Sometimes also deleting *.snap files.
Please backup the whole workspace (including projects) first!
Close eclipse.
Copy your wanted project files (ie. workspace\Homework) to a temp directory, not the entire workspace.
Start eclipse.
Create a new workspace (you stated you could).
Delete the old workspace (might be able to this before previous step).
Import project from temp directory into new workspace.
Save!
Close and re-open eclipse.
The "NEW INFO" section makes it look like you are out of disk space on the system. Have you checked?

Removing an unwanted directory folder from netbeans and fixing a "is already under version control"

I have two issues i would like to get fixed, yet in my attempt to fix the issues i have managed to descend down to an angry primate screaming and shouting at my pc.
Here are my issues (some of which cannot be solved by an online community),
Earlier today i thought it would be a great idea to create a folder called "res", res would be used to store images and wav files for a game i am making. Now, if the wav file i am testing is not inside this folder and the directory to the wav file is right it works fine, it looks like this ".getResource(fileName);". But when i do have the wav file in the "res" folder, i changed the directory to the following .getResource("res/"+fileName); i get the following
warning: [options] bootstrap class path not set in conjunction with -source 1.6
1 warning
as well as a nullPointerException pointing to all the stuff relating to sound.
So after being incredibly frustrated, i removed "res" folder, then the project stopped compiling as it cannot find "res", so i recreated res folder, keeping the wav file out of it which worked just fine. I then felt happy about it and thought, ya i'm done for a while, lets commit this to SVN.
On attempt to commit my work i get a "is already under version control" error for the "res" folder
so to recap this
i created a folder called "res" in my project folder (via netbeans)
i put a wav file into "res" and found it threw errors
i removed the wav file from "res" and it worked just fine
i deleted res folder and project refused to compile without this very important folder
i recreated res folder and then tried to commit my work to SVN and SVN doesn't want my children anymore.
I am now left with children i cannot put somewhere safe and an unwanted ghost in my house (folder in my project folder that wont do anything)
assistance, as always is greatfully accepted and welcomed.
With respect to the SVN problem:
NB tends to add or delete directories on SVN automatically (but not commit) and it might be confused after the delete/recreation.
I'd suggest using a different tool (SVN command line or TortoiseSVN, for example) to verify which operations does SVN are pending and try reverting operations on the res directory. If SVN marks res as existing then you might try veryfing that the directory is not already on the repository.
Also you might remove the SVN cache from your Netbeans directory (previously called %HOME%\.netbeans\cache\svn and now (NB 7.2) changed to %HOME%\Netbeans\Cache\7.2\svncache.
An extreme solution would be to make a new checkout and copy your changes from the old working copy to the new one.

Categories