javac file has wrong version 51.0, should be 49.0

560 views
Skip to first unread message

Michael Pope

unread,
Nov 24, 2014, 8:55:49 PM11/24/14
to mlu...@googlegroups.com
I'm running Debian stable (7.6) 64bit and have installed Oracle JDK 7
manually under /opt/jdk1.7.0, this has been running programs for a while
and that still works. What is broken though is I cannot compile
something with javac.

If I run javac HelloWorldApp.java I get the following error
HelloWorldApp.java:5: cannot access java.lang.Object
bad class file: /opt/jdk1.7.0/jre/lib/rt.jar(java/lang/Object.class)
class file has wrong version 51.0, should be 49.0
Please remove or make sure it appears in the correct subdirectory of the
classpath.
class HelloWorldApp {
^
1 error

Here is the code;
/**
* The HelloWorldApp class implements an application that
* simply displays "Hello World!" to the standard output.
*/
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); //Display the string.
}
}


They are the same version

$ java -version
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) 64-Bit Server VM (build 21.0-b17, mixed mode)

$ javac -version HelloWorldApp.java
javac 1.7.0

They point to the same area

$ update-alternatives --display java
java - auto mode
link currently points to /opt/jdk1.7.0/bin/java
/opt/jdk1.7.0/bin/java - priority 1065
/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java - priority 1061
slave java.1.gz: /usr/lib/jvm/java-6-openjdk-amd64/jre/man/man1/java.1.gz
/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java - priority 1051
slave java.1.gz: /usr/lib/jvm/java-7-openjdk-amd64/jre/man/man1/java.1.gz
Current 'best' version is '/opt/jdk1.7.0/bin/java'.

$ update-alternatives --display javac
javac - auto mode
link currently points to /opt/jdk1.7.0/bin/javac
/opt/jdk1.7.0/bin/javac - priority 1065
Current 'best' version is '/opt/jdk1.7.0/bin/javac'.



--
from
Michael

Darren Wurf

unread,
Nov 24, 2014, 11:09:18 PM11/24/14
to mlu...@googlegroups.com
On Tue, Nov 25, 2014 at 12:55 PM, Michael Pope <map...@gmail.com> wrote:
> If I run javac HelloWorldApp.java I get the following error
> HelloWorldApp.java:5: cannot access java.lang.Object
> bad class file: /opt/jdk1.7.0/jre/lib/rt.jar(java/lang/Object.class)
> class file has wrong version 51.0, should be 49.0
>

I'm guessing you have a JDK1.5 installed on your system[1]. For
whatever reason, that's getting involved in the compilation process.
Try using the full path to javac, do you get the same result?

Cheers,

Darren

[1] http://java67.blogspot.com.au/2012/10/how-to-fix-javalangunsupportedclassversionerror-major-minor-version-49-50-51.html

Darren Wurf

unread,
Nov 24, 2014, 11:14:01 PM11/24/14
to mlu...@googlegroups.com
Oh, and don't forget to:
export JAVA_HOME=/opt/jdk1.7.0/

--
Darren

Michael Pope

unread,
Nov 24, 2014, 11:25:14 PM11/24/14
to mlu...@googlegroups.com
I don't have Java 5 or 6 installed, I just have two versions OpenJDK-7 &
Oracle-7-Java.

I do have JAVA_HOME=/opt/jdk1.7.0 and it still results in the same error
message when compiling. I've gone to the extent now of creating a VM and
building it (with ansible scripts) the same as my server and it works.
So now I'm comparing the two. It doesn't make any sense.



from
Michael

Darren Wurf

unread,
Nov 24, 2014, 11:44:54 PM11/24/14
to mlu...@googlegroups.com
Hmm. This error seems to indicate you're accessing a java7 copy of the
JRE standard libs from a java5 environment. Check your environment
variables for any java-related stuff, maybe some variable is
triggering cross-compilation. Scan your drive for rogue JVMs/JDKs
installed by other software (eg eclipse-based stuff, proprietary java
apps, other Java-dependent IDEs, etc etc)

Cheers,

--
Darren

Michael Pope

unread,
Nov 24, 2014, 11:54:31 PM11/24/14
to mlu...@googlegroups.com
I just got it working by cheating off my VM install and changing the
javac to the following
sudo update-alternatives --set javac
/usr/lib/jvm/java-7-openjdk-amd64/bin/javac

lrwxrwxrwx 1 root root 22 Jun 7 2013 /etc/alternatives/java ->
/opt/jdk1.7.0/bin/java
lrwxrwxrwx 1 root root 43 Nov 25 15:51 /etc/alternatives/javac ->
/usr/lib/jvm/java-7-openjdk-amd64/bin/javac
lrwxrwxrwx 1 root root 45 Nov 25 15:47 /etc/alternatives/javadoc ->
/usr/lib/jvm/java-7-openjdk-amd64/bin/javadoc
lrwxrwxrwx 1 root root 55 Nov 25 15:47 /etc/alternatives/javadoc.1.gz ->
/usr/lib/jvm/java-7-openjdk-amd64/man/man1/javadoc.1.gz
lrwxrwxrwx 1 root root 43 Nov 25 15:47 /etc/alternatives/javah ->
/usr/lib/jvm/java-7-openjdk-amd64/bin/javah
lrwxrwxrwx 1 root root 53 Nov 25 15:47 /etc/alternatives/javah.1.gz ->
/usr/lib/jvm/java-7-openjdk-amd64/man/man1/javah.1.gz
lrwxrwxrwx 1 root root 43 Nov 25 15:47 /etc/alternatives/javap ->
/usr/lib/jvm/java-7-openjdk-amd64/bin/javap
lrwxrwxrwx 1 root root 53 Nov 25 15:47 /etc/alternatives/javap.1.gz ->
/usr/lib/jvm/java-7-openjdk-amd64/man/man1/javap.1.gz

I don't like this solution though. If I use the /opt/jdk1.7.0/bin/javac
to compile something it still shows the error.

I think something is wrong with the /opt/jdk1.7.0 directory, maybe I
need to reinstall this.

from
Michael

Darren Wurf

unread,
Nov 25, 2014, 12:06:54 AM11/25/14
to mlu...@googlegroups.com
> I think something is wrong with the /opt/jdk1.7.0 directory, maybe I
> need to reinstall this.
>

Cheap hack: copy /opt/jdk1.7.0 out of your VM :)

Michael Pope

unread,
Nov 25, 2014, 12:22:16 AM11/25/14
to mlu...@googlegroups.com
I copied /opt/jdk1.7.0 from my broken machine to my VM, so they are
already the same.

I only need /opt/jdk1.7.0 for the mozilla plugin so I've reverted java &
javac back to using openjdk and that works, so I'm going to leave it
like that for now.

from
Mick
Reply all
Reply to author
Forward
0 new messages