Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Debugger shows incorrect variable values(Eclipse is loading the incorrect .class file)
Debugger shows incorrect variable values [message #1076008] Tue, 30 July 2013 14:07 Go to next message
Jim Anderson is currently offline Jim AndersonFriend
Messages: 109
Registered: October 2014
Senior Member
I am debugging some code and have found that Eclipse is not always staying up to date with the source code. I verified this by putting some print statements in my source code. If I run the program in a batch mode, the output values are correct, but in Eclipse the values are not correct.

My *.class files are co-located with the *.java files, so I would expect that
Eclipse would update each .class file when changes are made to the source files,
but this does not seem to be the case. When I make changes to the source file, the
source window in the debug perspective reflects the change, but when I run the code,
the object file has not been updated in Eclipse.

I suspect the problem may be that I have linked my workspace source to an external
source. This link points to the area on disk where I maintain my CVS controlled
source code. When I look at my workspace, I see that under my java project there
is a 'bin' directory that has jar files matching up to the jar files that I normally
build when in batch mode. By 'matching up' I mean that the jar files in the workspace
match up to the jar files in the CVS area and are in the same relative directory.
When I change a source file and do a build, the jar files in both areas get rebuilt.

My best guess is that Eclipse is not updating the version of xxx.class when
xxx.java is changed. I experimented and changed the source code for my xxx.java.
The jar file in my workspace was automatically updated by Eclipse, but the xxx.class file remained out of date. I can only guess that Eclipse is using the out
of date .class file. It should either be using the up to date jar file or
updating the .class file, if I am correct.

I did some additional checking in Eclipse and found that there is a
window --> preferences --> java --> build path --> 'source and output folder'
preference. For my project this was set to 'folders' and the values were
'src' and 'bin' for the source and output folders. This explains why
there is a 'bin' directory for my project. Under the 'bin' directory, I
find the same relative paths as in my 'src' directory. I find that my
xxx.class file is getting updated under the 'bin' directory, and not
under the 'src' directory.

Is there a 'preference' that can be set to instruct Eclipse to use the xxx.class
file in my 'src' directory, not the xxx.class file in the subdirectory
under 'bin' or the jar file?

Thank you in advance.

Jim Anderson

[Updated on: Tue, 30 July 2013 15:14] by Moderator

Report message to a moderator

Re: Debugger shows incorrect variable values [message #1076014 is a reply to message #1076008] Tue, 30 July 2013 14:18 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
First: how do you build your project? Is Ant or Maven involved? If Maven, do you use m2e?
Having a bin folder *plus* having .class files co-located with .java files is odd.
Who is creating the co-located .class files?
What creates the jar file?

Stephan
Re: Debugger shows incorrect variable values [message #1076043 is a reply to message #1076014] Tue, 30 July 2013 15:23 Go to previous messageGo to next message
Jim Anderson is currently offline Jim AndersonFriend
Messages: 109
Registered: October 2014
Senior Member
>>> First: how do you build your project? Is Ant or Maven involved? If Maven, do you use m2e?

No, gmake is being used.

>>> Having a bin folder *plus* having .class files co-located with .java files is odd.

The bin folder was created when my project was created. I was unaware that it was
being created. I have been checking and I have found that there is a preference
that the source and output can be in the same folder. Because this is in odd set up,
I should start over and recreate the project using the same folder for source and output.


>>> Who is creating the co-located .class files?

The makefiles create .class files in the directory where the source is
which is in my CVS controlled area.


>>> What creates the jar file?

jar files are created by makefiles in my CVS ares. Somehow Eclipse is building the same jar files in the workspace.
Re: Debugger shows incorrect variable values [message #1076051 is a reply to message #1076043] Tue, 30 July 2013 15:43 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
That's an unusual configuration, I'd say.

JDT has much better idea of your .java and .class files if you just let it do all compiling by itself.

Now, if you tell JDT to place the .class files next to the .java files and if concurrently you run make, you can easily run into conflicts. To avoid those you have two options:
- disable .java->.class compilation in your makefile (or just don't invoke make during development), or
- disable the Java Builder under yourproject > Properties > Builders

One thing still looks strange: "Eclipse is building the same jar files": this doesn't just happen unless some plug-in / configuration tells Eclipse to do so.

HTH,
Stephan
Re: Debugger shows incorrect variable values [message #1076083 is a reply to message #1076051] Tue, 30 July 2013 17:26 Go to previous messageGo to next message
Jim Anderson is currently offline Jim AndersonFriend
Messages: 109
Registered: October 2014
Senior Member

Ideally, what I want to do is use the same source code for both Eclipse and for my batch processing outside of Eclipse and then
do my builds of .class files for Eclipse in my Eclipse workspace and for my external builds in another sandbox.

To accomplish this, I tried to build my Eclipse project so that Eclipse will direct output to a separate directory, not the
linked source directory. Eclipse allows me to do this which is great. However, the problem is that when I try to debug, Eclipse
is not building a new class file in the output directory when the source code changes. I think this is a bug in my configuration
or in the JDT.

What I am trying to do worked fine until my disk got full and I had to relocate data, including my Eclipse
workspace, to another disk. I know Eclipse can handle what I want to do, but I don't know how to configure the
JDT to look at (linked) source directory .java files to know when to update the .class files in my output
directory. I know it knows about the output .class files because it creates them. And I know it knows the
source file locations because I can view them in the JDT.

It is not clear to me, if there is a setting or preference in the JDT which tells the JDT where to look
for the .class file. As far as I know, there are no plugins, unless some plugins are included with the
downloaded tar.gz file I used to install Kepler.

Thanks for the comments so far. I'm still experimenting, trying to get things to work, but so far, no luck.

Jim
Re: Debugger shows incorrect variable values [message #1076085 is a reply to message #1076083] Tue, 30 July 2013 17:34 Go to previous message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
What kind links do you use? Do you create them at the OS level, or using the Import wizard and selecting "Create links in workspace" (with sub-option?)?

As for an option where to look for .class files: are you asking about the Java Build Path (compile-time) or Classpath (runtime)?
Previous Topic:Groovy Eclipse - New / unexpected error message with Kepler
Next Topic:Project help
Goto Forum:
  


Current Time: Fri Apr 26 10:45:15 GMT 2024

Powered by FUDForum. Page generated in 0.03515 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top