0

I actually figured out the answer to my question just before clicking the "Post" button, but this has been so frustrating for me, I am going ahead and posting it in the hopes that it will help someone else. The answer is below.

I am using Eclipse Kepler, which is built with Java 1.7 (but I don't think that comes into play in this issue). My problem is that I'm ending up with different versions of java in different projects.

I have several related projects, I'll call them BV_S, BV_A, and BV_L. Before I took over this work, there was an ugly Subversion External thing set up so that the BV_A and BV_L project would each pull in some java source files from deep in the bowels of the BV_S project. To clean this up, I decided to pull all that shared source out and create a new BV_Common project, which would create a BV_Common.jar file, and then I'd use that .jar in building each of the three existing projects. Historically, these projects used a mixture of Java 1.5 and 1.6. My intent is to do everything with 1.6.

I've created the BV_Common.jar file, checked it into Subversion, and set up Subversion External properties in the other projects so that this .jar file is available in each of the BV_S, BV_A, and BV_L projects, and modified the Properties for each of the three projects to include BV_Common.jar.

When I run the build.xml script in each of these projects using "Run as ANT script", I get differing results. BV_L builds just fine. BV_A and BV_S both get the dreaded "bad class file blah blah BV_Common.jar . . . class file has wrong version 50.0, should be 49.0" error -- an indication that I'm trying to use a .jar file built with Java 1.6 while running java 1.5.

In all these projects, the build.xml file references an elaborate collection of shared build XML files (pulled in from a single common source). One of the things these files do is print out the value of "java.version". For the BV_L project, it's reported as 1.6.0_30; for BV_S and BV_C it's 1.5.0_14. So somehow, somewhere, these projects are being told to use (or be compatible with?) Java 1.5. But for the life of me, I can't figure out where.

Here's what I've looked at. In all cases, the values I see are identical on all four projects (BV_Common, BV_L, BV_C and BV_S):
In the project Properties screen, Java Build Path, on the Libraries tab, the JRE System Library is set to use the "Execution environment" of "JavaSE-1.6 (jdk1.6.0_30)".
In the project Properties screen, Java Compiler, the "Enable project specific settings" box is checked, and under JDK Compliance, the "Use compliance from execution environment 'JavaSE-1.6' on the 'Java Build Path'" checkbox is checked.
In each project, there is a .settings folder, and within that, a org.eclipse.jdt.core.prefs file. These files are byte-for-byte identical from project to project. In particular, they each contain these lines:
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.source=1.6
In each project, there is a .project file (which I presume controls Eclipse); these files are all identical except for the project name.

Each project has a .classpath file, and these differ because each project has a different set of various .jar files it needs, but they all contain the line
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
and they contain nothing else that looks like a java compiler, JDK, or JRE specification.

The build.xml script for BV_Common is different from the others, because it's creating a .jar file, but the remaining three projects are all nearly identical in their build scripts. They differ only in the following:
project.name property
project.jvm_arguments property -- one specifies an additional -D option to identify a configuration file.

But somewhere, something is associating Java 1.5 with my BV_L and BV_S projects.
I've tried shutting down and restarting Eclipse.

2
  • 2
    this could be a winning Essay of the year Commented Mar 6, 2014 at 1:15
  • Thanks, I had no idea there was such a thing. I hope this helps at least one person. Commented May 7, 2014 at 17:08

1 Answer 1

1

As mentioned at the top, somehow just after typing in this wall of text, it dawned on me what I needed to check. Here's what was going on.

The clue was in that "historically, these projects used a mixture of Java 1.5 and 1.6". When I first started working with these projects on my workstation, in each project, I right-clicked on the build.xml file, and did "run as Ant Script". This worked fine, but unbeknownst to me, in each case created a .launch (aka External Tool Configuration) file that contained information including the Java version to use, taken from the Properties of the project. In some cases, this was 1.5. These .launch files are, by default, hidden off in some Eclipse directory somewhere, not in the project directory with all the other files that control the project and its building. To do anything with these Launch Configurations, one must click on the little button with a red suitcase, select External Tools Configurations, and then work with the resulting dialog. One of the tabs is "JRE", and there, one can specify which JRE to use with the Ant build, much as one can in Project Properties / Java Build Path / Libraries -- but these specifications of which JRE to use are separate, and are connected only when the Launch configuration is first created. So you can be running one version of Java when debugging and executing from Eclipse, and a different version of Java when building with Ant.
Note that if you only ever launch your Ant build script by right-clicking on it and selecting "Run as Ant Script", and you never click on the little red suitcase, you will never be aware of these Launch Configurations, but they will be used anyway.

You do have the choice within the External Tool Configuration dialog to select whether the configuration (.launch file) will be saved as a "Local File" (the default) or "Shared File". I find this terminology confusing. "Local File" means hidden off in some Eclipse directory on your local workstation, and not shared with others who work on this project. "Shared file" means in your Eclipse workspace directory for that project, where you can see it and check it into Subversion, and other developers who check out the project will get the same configuration for their Ant builds. I recommend the latter.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.