This may seem a weird Q.
I had written a code in Java (in Eclipse). Then, I did some modifications to the code. Now, I am trying to run the new code (modified), but it is still giving me the output which it was giving for the previous code.
I have put few debug points in the code, but it is skipping some of the debug points (though it should stop at them) and stopping at some debug point, but even here it is calling the methods which were present in previous code at that location (though I have commented them now). It seems from somewhere it is still debugging the old code.
How to get rid of it?
Thanks!
Have you tried cleaning the project?
Project(menu) -> clean
Also make sure
Project(menu) -> Build Automatically
is selected so that all new code you write is compiled then and there
If the clean and build doesn't work, it's possible that there is a jar file contains the class you edited, so the eclipse will run the compiled class file in the jar instead of your current file.
There are two possibilities because of which the java code is not updating properly:
Project -> Build Automatically is not checked
In .project file of Project org.eclipse.jdt.core.javabuilder build command is commented or missing. Here the below mentioned piece of code should not be commented:
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments></arguments>
</buildCommand>
I had the same issue. I cleared out some code in Eclipse that printed to the console but these changes weren't reflected when I ran the code from command line. I am creating and executing a jar file from my code. Turns out I forgot to recompile after I made changes. So the following resolved the issues:
javac packageName/*.java
Now when I create my jar file, it will reflect the changes.
I've run into this issue lately - new code stops working. I click clean - then it can't find the main class anymore and the program won't run at all.
The fix I've found (works every time) is refactor - rename the project. This instantly fixes it. Then I just change the name back. Then after a couple days it happens again and I have to rename it again to fix it.
Related
I am new to Java and I found something super weird. I imported a project into my eclipse and tried to made some changes to it.
However, no matter what I did the output of the project remained the same even after I commented out the entire Main class.
Anyone has a clue why this is happening ?
It's likely that your project cannot built due to some critical problem (missing required library, unable to write to the output directory, etc.). Please check "Errors/Warnings" view, there should be some hint.
Looks like you had compiled classes in the target directory. Do a Project > Clean before you run.
Having strange problem for couple of days.
I have written 2 main files, so to test based on need.
I have been facing following strange problems,
The main fail stops executing after some statement. doesnt hang! after cleaning the build, and compiling again it got executing!
I updated few System.out.println statements, but i am cant see new statements.
I excluded the unwanted main files and tried. even commented the whole unwanted main files and tried.
I even tried changing the main file name that i am using.
I observe the eclipse is not compiling the main file i wanted or it is taking old class file some where residing?
I cant see the unwanted class anywhere in the workspace!!
anyone experienced similar problem?
Please try right-mouse click on the class in "Package Explorer", then
form the menu choose "Run As" -> "Java Application".
This will run (and compile if needed) the selected source code.
I copied a main file from other project, and that package got retained in that file. when i modify the code in copied main file, forgot to modify a constructor name which was pointing to earlier package. I missed to trace import statements and it was not expanded. when i try to copy the file to post in stackflow, i found earlier package was included and found that was the culprit!!
I am using IntelliJ IDEA. And my IDE saves my source code automatically before each compile. I am so accustomed to this feature so I even forgot that IDEA does this for me. Looks like whenever I ran Gradle "test" task, IDEA does not saves my source code automaticly, so test results might be incorrect.
Console output almost allways it looks like this:
some-task : UP-TO-DATE
But if I save source code manually everything works fine.
Is there a way to overcome this problem without manually saving source code before each test run?
If you go to the Settings dialog (CTRL + ALT + S on Windows) under the Project Settings > Compiler section there is a setting called 'Make project automatically'. Perhaps enabling that setting will cause the changes to be saved as you go (and avoiding your problem)?
I just started using Eclipse so go easy on me ;). But when trying to debug a JUnit test case I get a dialog that states the the source is not found when I get to this line in the code in my test method:
Assert.assertEquals(1, contents.size());
I know I should probably go and try and download the source from somewhere, but I really don't want to because I have no interest in stepping into the JUnit code. I have the JUnit runtime jar so Why does Eclipse expect me to have all the referenced tools source code in order to debug my own code (seems somewhat silly)?
My main question is though, how can I tell Eclipse to skip this dialog when the source is not available and allow me to continue to debug my own code?
[Edit]
I've isolated the cause of this. It seems that Eclipse seems to think it needs the source when an exception is thrown by the internal JUnit code. In general is there anyway to tell it that it doesn't and just have it throw up an error dialog of some kind instead?
I had this very annoying problem for a long time but was finally able to solve it. In my case, a null pointer exception was being thrown somewhere in Java's Transformer.IsRuntimeCode(ProtectionDomain) function.
I didn't really need to know about this since the exception was being caught and handled, but eclipse would pause debugging every time this happened and tell me that the source wasn't available. As a result, I constantly had to keep pressing the button to continue code execution.
In order to prevent this from happening, I:
Clicked on the "Breakpoints" window
at the bottom of the debugging
screen
Right clicked "NullPointerException"
Unchecked "Caught"
This prevented the debugger from pausing program flow during a caught NullPointerException.
(source: SharpDetail.com)
The debug callstack will display a JUnit source code line when throwing an exception.
But you should not need to worry about that, if you do not have the source code of JUnit.
If you go back one line in the callstack, you should see the line (of your source code) which has caused the JUnit exception.
That should be enough to debug your code.
To associate the source with JUnit, you could add the junit.jar in the librairies of your project, and associates the junit-x.y.z-src.jar to the junit-x.y.z.jar, like so:
That will generate in the .classpath of your project a line like:
<classpathentry kind="lib" path="junit-x.y.z.jar" sourcepath="junit-x.y.z-src.jar">
Note: actually, there would be the full path of the junit[...].jar files in this classpathentry line. But you could also use Linked resources to avoid that fixed value (the full path) in your .classpath file.
I had a similar problem. I fixed it by right clicking on the project folder in the package explorer and selecting refresh. The code source was out of sync with the debugger and this corrected it. The Transformer.IsRuntimeCode(ProtectionDomain) Source not found message no longer appears.
Calculate contents.size() on a separate line instead or set a breakpoint on the method.
Also note the junit view in Eclipse allows you to navigate the stack trace.
Use the Step Filter to avoid stepping through the ...junit... packages. Right click on the stack trace and choose Filter Package. You may have to turn on filtering first with Use Step Filters. ~~~
I had a similar problem with another jar, even when I pointed to the source it would ask for it again. I was able to solve it by compiling the jar with debug="on" on ANT.
I have a Maven Java project, imported using m2eclipse.
The target/ directory is not marked as 'Derived' by m2eclipse.
Problems:
It is validated, so any validation error appear twice. My example shows a JSP Problem, when I insert intentionally an error in a jsp.
When I want to open a resource with Ctrl-Shift-R, all files appear twice, and I run the risk of editing the copy instead of the original file.
Possibly see post eclipse-ignore-folder
Note: When I set manually the directory to derived, the validation problem doesn't disappear, so that would only be part of the solution...
Question:
Is there something I need to do, so that m2eclipse sets the target/ directory to 'Derived' ?
Yeah, that has been around for a while. I wrote a plug-in that allows you to mark directories as "derived" without having to find them all (http://eclipsefrills.sourceforge.net/). It's not great, and you still have to manually run the action to make it work, but it may help.
Odd, though, I have not noticed the problem lately, myself. I wonder if there is some setting in the preferences that takes care of this now.
Good luck.
I got rid of this problem by writing a custom plug-in KeepTargetDerivedPlugin. As its name suggests, it automatically keeps all target folders derived (unlike the other solutions, which require user action).
Still, e. g. the YA2O's plug-in can be used to mark derived folders of projects which already reside in the given Eclipse workspace.
Yes: open a bug report :)
I have been so annoyed by this problem that I wrote a plugin to solve it. You can get the source and jar from here.