Eclipse class version bug - java

In eclipse 3.4 I'm trying to do some performance tests on a large product, one of the included libraries is the vecmath.jar (javax.vecmath package) from the Java3D project. Everything was working fine and then when trying to run it yesterday I get this exception/error not long after starting it up:
java.lang.UnsupportedClassVersionError: javax/vecmath/Point2f (Unsupported major.minor version 49.0)
Which I believe means that I'm trying to load a java 1.5 class file into a 1.4 jvm which is unsupported. However when I went to the class file to check this I saw this in the eclipse class file viewer:
Compiled from Point2f.java (version 1.2 : 46.0, super bit)
So the class loader says it is version 49.0 but the class file says its 46.0. I've tried cleaning and fully rebuilding the project, I've confirmed that the compiler version for the project is 1.4, the JRE is 1.4 and for the run configuration the 1.4 jvm is selected. I'm totally stuck on this, does anyone have any idea what might be causing this?
Thanks
===EDIT===
It turns out that a version of java3d which was incompatible with java 1.4.2 had been installed in C:\Program Files\java\j2re1.4.2_18\lib\ext. I installed a newer version of Java3D to play around with in java6 and i guess it installed the libs in all my JREs even the ones which were incompatible.

Could there be another javax.vecmath.Point2f on your classpath?

I believe JRE 1.5 is required for the latest version of Java3D.

Have you checked:
Window
-> Preferences
-> Java
-> Compiler
-> Compiler Compliance Level
To see if this value is screwy?

You have to add the
"java_home : C:\Program Files\Java\jdk1.6.0_16"
"path: C:\Program Files\Java\jdk1.6.0_16\bin;"
to your Environment Variables!

Related

java version in not match for eclipse

I had java version 8 previous and my eclipse worked just fine. But now I have java version 7 and I can't open eclipse on my computer. What should I do? please help.
I think there are two options:
Upgrade to Java version 8 (or newer).
If you can't do that, downgrade to a version of eclipse that supports Java 7. eclipse 4.5 (Mars) (or earlier as noted on the linked page), as of eclipse 4.6 (Neon) Java 8 is required.
I feel I should note that newer versions of Java (and eclipse) can still target Java 7 (and many earlier versions).
But now I have java version 7 and I can't open eclipse on my computer. What should I do?
Use versions that work together. When you for example look at your second screen shot, it says something like "requiredJavaVersion=1.8" or so.
In other words: you can't just come in and run eclipse with any version of java.
The other answer gives you the required details.
And a final note here: in case you tried to start eclipse with that older JVM in order to "allow" to ensure that eclipse won't allow "java 8" stuff in a project: that isn't the right way then. Instead: eclipse allows you to "define" JDKs to be used for your project. So you can easily tell eclipse: "I have a Java7 jdk sitting here, please use that for project X".
You do not need to run eclipse itself with a Java7 JVM in order to use a Java7 JDK for an eclipse project!
There will be a file under the Eclipse installation directory named as eclipse.ini.
It will launch the eclipse for that specific jdf and you can change the path to your jdk7.
Hope it helps.
It depends basically on which version of the eclipse you have.
If you have eclipse 4.6(Neon) or the latest version, then you must need a newer JDK version of Java (>=1.8 which you need to download). Or If you want to roll back to an older version of Eclipse then consider downloading eclipse 4.5(Mars).
Or If you have an eclipse version of 4.5(Mars) or older then see in eclipse.ini
-Dosgi.requiredJavaVersion = 1.8 and change it to -Dosgi.requiredJavaVersion = 1.7 which can be found in the folder containing eclipse.exe file.

The type java.util.Comparator cannot be resolved

The type java.util.Comparator cannot be resolved. It is indirectly referenced from required .class files
I recently installed Java 8. While executing an application, I got above mentioned error can you please help me.
I am using:
Java - jdk1.8.0_51
Tomcat - apache-tomcat-5.5.26
Assuming you are using some IDE, like Eclipse. When you are using jdk 1.8 with IDE, you need to update your IDE to support version 1.8.
It does not matter you are using new jdk's feature or not, but compiler has to load new JRE files in order to compile your project.
If you are using IntelliJ, go to:
File/Settings/Build, Execution, Deployment/Compiler/Java Compiler
and make sure "Use compiler" and "Project bytecode version" have the right configuration.
I had this same error and tried many things to fix it, but finally worked was remarkably simple: It turns that I was simply using an older version of Eclipse that did not support a "Compliance Level" setting of Java that was as high as my JRE. I merely upgraded to a newer version and the problem went away.
From what I understand about "Compliance Level", it's the version of Java that your program is supposed to work on. That much I found out from reading stuff on the net. But what the other solutions did not mention is that your IDE has to be able to be set to a level as high as your JRE. In my case, I was using JRE 1.8, but the highest compliance level my older IDE supported was 1.6.
IMO, this situation should have been flagged as an error by Eclipse. But as it was, I wasted two nights trying to figure this out.
Your project build path could be referring to a jre instead of JDK.
Go to your build path. (In eclipse right click and choose build path).
Go to your libraries and replace the jre with the jdk.
pom.xml version is 1.6?
If this is the way,you would replace jdk1.8 with jdk1.6 ,and environment variable into jdk1.6。
Same strange problem occurred. It turned out that wrong jdk version was in JAVA_HOME
There you are I had the same issue but moment I saw your question i got it fixed. problem is you are not using old version since there is mismatch of referencing with new version. this error will come.
Work around:
1. Change your java version to old.(In my case I had to change to 7)
2. Update each libray and jar file compatible to java 8 that way it will refer java not class file
Here is the image of environment variable in my problem
check if build path is set to run with JDK. It is important point that JKD is software development kit while JRE is a runtime env. Advice who had this problem see the different between JDK, JRE and JVM. https://www.guru99.com/difference-between-jdk-jre-jvm.html

How to set eclipse with JRE 8?

I tried to update my jre version in eclipse,
I added the jre 8 to my installed JRE's an checked him.
When I click OK it gives me an ERROR:
The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from
required .class files
It happens only when I am trying to use JRE 8.
Someone know how to fix this?
I use Indigo Eclipse. Version: Service Release 2.
The problem is rt.jar in the JVM 8.0.
java.lang.CharSequence is a class under rt.jar.
rt.jar under JVM 7.0 has no problem, but rt.jar under JVM 8.0 has a problem with Eclipse Indigo. Solition is downloading Eclipse Kepler, JVM 8.0 with Kepler has no problem.
Create new workspace. Create new java project and select jvm8 as jvm. Changing the vm in an existing project is quite difficult and cached class file compiled with the previous vm can generate some strange unpredictable behavior
You need Eclipse Kepler (4.3) Service Release 2. After startup you need to install a patch that enables using Java 8 in eclipse from this update site (Help -> install new Software... -> use site):
http://download.eclipse.org/eclipse/updates/4.3-P-builds/
But a Android Project will not benefit from Java 8 because it still uses Java 6 and you cannot use Lambda Expressions or even the diamond Operator from Java 7.

How to change workspace JRE in Eclipse

While creating new Java project in Eclipse I got following warning "The current workspace uses 1.4 JRE..."
I have JRE7 on my system. I have added following lines in eclipse.ini
-vm
C:\Java\jre7\bin\javaw.exe
I have added JRE7 to Installed JREs through Windows -> Preferences-> Installed JREs.
Still under Compiler tab I can see only compiler compliance level till 6.
How can I change workspace JRE to JRE 7 ?
Java 7 support is only available since Eclipse Indigo SR1 (released about a month ago). So, upgrade Eclipse.
I also have jre7, and it really doesn't matter if it only says that is compliant with 1.6, because the project will look for the java compiler specified by the jre/jdk used in the project.
I also recommend you use the jdk instead of the jre, and set the environment variable JAVA_HOME, there's lots of tutorials on this in Google.
The issue where it is compiling with 1.4 but the workspace Preferences Compiler setting is 1.6 seems to be the issue described in this bug:
Bug 499675 - Global compiler settings ignored after restarting, defaults to 1.4 even though 1.8 displayed
https://bugs.eclipse.org/bugs/show_bug.cgi?id=499675
where the workaround is to change the workspace setting to a different version number and then back to 1.6. That would enable the workspace to compile with 1.6.
To compile with 1.7 you'd need to upgrade eclipse as in BalusC's answer.

java.lang.UnsupportedClassVersionError in eclipse [duplicate]

This question already has answers here:
How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version
(51 answers)
Closed 6 years ago.
I am not a Java programmer really, so I am posting this question. The exception is being thrown java.lang.UnsupportedClassVersionError in my main class in an eclipse project. If I comment out the imports that this class has, it compiles and runs fine. If I put the imports back in, it does not work. Does this mean that the libraries I am importing were compiled with a newer or older version of java than I have? when i do java -version on the system i get 1.5_07
I could've sworn this was actually working last week, but maybe some setting in eclipse got tweaked? Is the Java Build Path in eclipse what I need to look for to check the JRE and compiler versions?
In Eclipse, the compiler version is set independent of the JRE version. That means you can set the compiler to Java version 1.6 and use the JRE 1.5. In this case, you compiled classes cannot be run.
You can check the preferences in Window / Preferences / Java / Compiler for the default compiler compliance level, or the properties of your project for a project specific compiler compliance level. Compare that level with the JRE used in your project (Project / Properties / Java Build Path -> Libraries / JRE System Library) and in your program's launch configuration (via the Run / Run Configurations... menu).
UnsupportedClassVersionError means that the Java runtime environment you are using doesn't recognise the version of a class file that you are trying to execute. The most common cause for this error is trying to use a class file compiled for a newer Java version on an older Java version - for example, you are trying to use a class compiled for Java 6 on a Java 5 runtime environment.
As Eugene explained, Eclipse has its own built-in compiler, it does not use the compiler from the JDK - so that's how you can end up with Java 6 class files even if you're running on Java 5.
Christian explains how to set the Java class file version in Eclipse.
Eclipse is not using JDK compiler, but has its own compiler which can produce bytecode for any JRE. You need to make sure that compiler settings in your project are set to the same or lower version as the JRE you have registered in Eclipse. See Window / Preferences / Java / Installed JREs and also check what JRE is used in your launch configuration (see Run menu for that).
If your imported classes come from an external library (i.e., not compiled from sources within your project), then you should validate that the JRE used for your project is new enough for this library.
If you are using Maven with Eclipse, you can use the Maven plugin to update the project and then do a Maven "clean" . This resolved a goofy and unexpected show of this error in my case.
I know this is an OLD thread now but I had a recent adventure with this type of error.
When trying to compile my project within Eclipse using an Ant build file.
Eclipse Kepler (Java 1.7)
Ant 1.7
Project = Java 1.5
All internal paths and compiler settings were amended to look at Java 1.5 and the project built fine in Eclipse.
When trying to compile using Ant I got the java.lang.UnsupportedClassVersionError in eclipse and began looking around - including on here and finding this page.
My resolution was this :
Windows > Preferences > Ant > Runtime > Global Entries
Global Entries was pointing at the Java 1.7 tools.jar
I added a new External Jar (on the right menu) and pointed it at the Java 1.5 tools.jar
I removed the original entry (for 1.7 tools.jar) and my ant builds started working.

Categories