You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@harmony.apache.org by karan malhi <ka...@gmail.com> on 2006/02/14 20:57:12 UTC

error when using sun compiler

Hi,

Tried to compile and run a simple hello world program. When I use the 
eclipse programmer, it works fine, but when I use the sun's jdk 
compiler, I get an error . I am still trying to get a feel of this 
project, so probably this was not supposed to work. Could you please 
help me understand why am I getting this error?

---------Eclipse Compiler -----------------------
[karan@j2ee bin]$ pwd
/home/karan/projects/Harmony/deploy/jre/bin

[karan@j2ee bin]$ javac -version
Eclipse Java Compiler v_579_R31x, 3.1.1 release, Copyright IBM Corp 
2000, 2005. All rights reserved.

[karan@j2ee bin]$ javac Test.java
[karan@j2ee bin]$ ./java Test
Hello World

-------Suns JDK --------------------------------
[karan@j2ee bin]$ ~/jdk1.5.0_06/bin/javac -version
javac 1.5.0_06

[karan@j2ee bin]$ ~/jdk1.5.0_06/bin/javac Test.java

[karan@j2ee bin]$ ./java Test
Exception in thread "main" java.lang.UnsupportedClassVersionError: 
(Test) bad major version at offset=6
        at java.lang.ClassLoader.defineClassImpl(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:271)
        at 
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:64)
        at java.net.URLClassLoader.findClassImpl(URLClassLoader.java:1087)
        at java.net.URLClassLoader$4.run(URLClassLoader.java:598)
        at 
java.security.AccessController.doPrivileged(AccessController.java:206)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:595)
        at 
com.ibm.oti.vm.URLSystemClassLoader.findClass(URLSystemClassLoader.java:25)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:631)
        at 
com.ibm.oti.vm.URLSystemClassLoader.loadClass(URLSystemClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:587)

-- 
Karan Singh


Re: error when using sun compiler

Posted by karan malhi <ka...@gmail.com>.
[karan@j2ee bin]$ ./java -version
java version 1.4.2 (subset)

(c) Copyright 1991, 2005 The Apache Software Foundation or its 
licensors, as applicable.

What I want to do is compile the class with sun jdk and run it within 
harmony. Is it possible to do something like that right now?

Thomas Engelschmidt wrote:

> Hi,
>
> Try java -version or which java - to clarify the version and path of 
> the java binary.
>
> regards
>
>
> karan malhi wrote:
>
>> Hi,
>>
>> Tried to compile and run a simple hello world program. When I use the 
>> eclipse programmer, it works fine, but when I use the sun's jdk 
>> compiler, I get an error . I am still trying to get a feel of this 
>> project, so probably this was not supposed to work. Could you please 
>> help me understand why am I getting this error?
>>
>> ---------Eclipse Compiler -----------------------
>> [karan@j2ee bin]$ pwd
>> /home/karan/projects/Harmony/deploy/jre/bin
>>
>> [karan@j2ee bin]$ javac -version
>> Eclipse Java Compiler v_579_R31x, 3.1.1 release, Copyright IBM Corp 
>> 2000, 2005. All rights reserved.
>>
>> [karan@j2ee bin]$ javac Test.java
>> [karan@j2ee bin]$ ./java Test
>> Hello World
>>
>> -------Suns JDK --------------------------------
>> [karan@j2ee bin]$ ~/jdk1.5.0_06/bin/javac -version
>> javac 1.5.0_06
>>
>> [karan@j2ee bin]$ ~/jdk1.5.0_06/bin/javac Test.java
>>
>> [karan@j2ee bin]$ ./java Test
>> Exception in thread "main" java.lang.UnsupportedClassVersionError: 
>> (Test) bad major version at offset=6
>>        at java.lang.ClassLoader.defineClassImpl(Native Method)
>>        at java.lang.ClassLoader.defineClass(ClassLoader.java:271)
>>        at 
>> java.security.SecureClassLoader.defineClass(SecureClassLoader.java:64)
>>        at 
>> java.net.URLClassLoader.findClassImpl(URLClassLoader.java:1087)
>>        at java.net.URLClassLoader$4.run(URLClassLoader.java:598)
>>        at 
>> java.security.AccessController.doPrivileged(AccessController.java:206)
>>        at java.net.URLClassLoader.findClass(URLClassLoader.java:595)
>>        at 
>> com.ibm.oti.vm.URLSystemClassLoader.findClass(URLSystemClassLoader.java:25) 
>>
>>        at java.lang.ClassLoader.loadClass(ClassLoader.java:631)
>>        at 
>> com.ibm.oti.vm.URLSystemClassLoader.loadClass(URLSystemClassLoader.java:56) 
>>
>>        at java.lang.ClassLoader.loadClass(ClassLoader.java:587)
>>
>
>

-- 
Karan Singh


Re: error when using sun compiler

Posted by Thomas Engelschmidt <te...@zama.org>.
Hi,

Try java -version or which java - to clarify the version and path of the 
java binary.

regards


karan malhi wrote:

> Hi,
>
> Tried to compile and run a simple hello world program. When I use the 
> eclipse programmer, it works fine, but when I use the sun's jdk 
> compiler, I get an error . I am still trying to get a feel of this 
> project, so probably this was not supposed to work. Could you please 
> help me understand why am I getting this error?
>
> ---------Eclipse Compiler -----------------------
> [karan@j2ee bin]$ pwd
> /home/karan/projects/Harmony/deploy/jre/bin
>
> [karan@j2ee bin]$ javac -version
> Eclipse Java Compiler v_579_R31x, 3.1.1 release, Copyright IBM Corp 
> 2000, 2005. All rights reserved.
>
> [karan@j2ee bin]$ javac Test.java
> [karan@j2ee bin]$ ./java Test
> Hello World
>
> -------Suns JDK --------------------------------
> [karan@j2ee bin]$ ~/jdk1.5.0_06/bin/javac -version
> javac 1.5.0_06
>
> [karan@j2ee bin]$ ~/jdk1.5.0_06/bin/javac Test.java
>
> [karan@j2ee bin]$ ./java Test
> Exception in thread "main" java.lang.UnsupportedClassVersionError: 
> (Test) bad major version at offset=6
>        at java.lang.ClassLoader.defineClassImpl(Native Method)
>        at java.lang.ClassLoader.defineClass(ClassLoader.java:271)
>        at 
> java.security.SecureClassLoader.defineClass(SecureClassLoader.java:64)
>        at java.net.URLClassLoader.findClassImpl(URLClassLoader.java:1087)
>        at java.net.URLClassLoader$4.run(URLClassLoader.java:598)
>        at 
> java.security.AccessController.doPrivileged(AccessController.java:206)
>        at java.net.URLClassLoader.findClass(URLClassLoader.java:595)
>        at 
> com.ibm.oti.vm.URLSystemClassLoader.findClass(URLSystemClassLoader.java:25) 
>
>        at java.lang.ClassLoader.loadClass(ClassLoader.java:631)
>        at 
> com.ibm.oti.vm.URLSystemClassLoader.loadClass(URLSystemClassLoader.java:56) 
>
>        at java.lang.ClassLoader.loadClass(ClassLoader.java:587)
>


Re: error when using sun compiler

Posted by Alexey Petrenko <al...@gmail.com>.
> Actually I had to also specify the version of the
> source.
I'm not using this options very often :)

--
Alexey A. Petrenko
Intel Middleware Products Division

Re: error when using sun compiler

Posted by karan malhi <ka...@gmail.com>.
Thanks Alexey,

This works now. Actually I had to also specify the version of the 
source. When I only specify the -target this is what I get:
[karan@j2ee bin]$ ~/jdk1.5.0_06/bin/javac -target 1.4 Test.java
javac: target release 1.4 conflicts with default source release 1.5

However, when i specify both -source and -target, it works fine.
[karan@j2ee bin]$ ~/jdk1.5.0_06/bin/javac -target 1.4 -source 1.4 Test.java
[karan@j2ee bin]$ ./java Test
Hello World


Alexey Petrenko wrote:

>>-------Suns JDK --------------------------------
>>[karan@j2ee bin]$ ~/jdk1.5.0_06/bin/javac -version
>>javac 1.5.0_06
>>
>>[karan@j2ee bin]$ ~/jdk1.5.0_06/bin/javac Test.java
>>
>>[karan@j2ee bin]$ ./java Test
>>Exception in thread "main" java.lang.UnsupportedClassVersionError:
>>(Test) bad major version at offset=6
>>    
>>
>It easy :)
>You've compiled a class with 1.5 compiler and then run it on 1.4 VM.
>You can fix this issue by two ways:
>1. Complile the class with -target 1.4 javac option
>(~/jdk1.5.0_06/bin/javac -target 1.4 Test.java) and run as ./java Test
>2. Compile without target option as you did it before and run on 1.5
>VM (~/jdk1.5.0_06/bin/java Test)
>
>This should help.
>
>--
>Alexey A. Petrenko
>Intel Middleware Products Division
>  
>

-- 
Karan Singh


Re: error when using sun compiler

Posted by Alexey Petrenko <al...@gmail.com>.
> -------Suns JDK --------------------------------
> [karan@j2ee bin]$ ~/jdk1.5.0_06/bin/javac -version
> javac 1.5.0_06
>
> [karan@j2ee bin]$ ~/jdk1.5.0_06/bin/javac Test.java
>
> [karan@j2ee bin]$ ./java Test
> Exception in thread "main" java.lang.UnsupportedClassVersionError:
> (Test) bad major version at offset=6
It easy :)
You've compiled a class with 1.5 compiler and then run it on 1.4 VM.
You can fix this issue by two ways:
1. Complile the class with -target 1.4 javac option
(~/jdk1.5.0_06/bin/javac -target 1.4 Test.java) and run as ./java Test
2. Compile without target option as you did it before and run on 1.5
VM (~/jdk1.5.0_06/bin/java Test)

This should help.

--
Alexey A. Petrenko
Intel Middleware Products Division