File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Exception: java.lang.ClassVersionError: Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Exception: java.lang.ClassVersionError: " Watch "Exception: java.lang.ClassVersionError: " New topic
Author

Exception: java.lang.ClassVersionError:

ajay yaduwanshi
Greenhorn

Joined: Oct 12, 2007
Posts: 28
Hi All,
I am getting this error while I am trying to execute my shell script

Exception in thread "main" java.lang.UnsupportedClassVersionError:
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)

the class files of the jave code formed by using version jdk1.5.0_10
and the script for running using j2sdk1.4.2_12.

Is there any way to make the class file made in jdk1.5.0_10 compatible to j2sdk1.4.2_12.

Please help me with this.

Thanks & Regards

Ajay Singh Yaduwanshi
Jan van Mansum
Ranch Hand

Joined: Oct 19, 2007
Posts: 74
Compile with -source=1.4
You won't be able to use class templates though.


SCJP 1.4, SCWCD 1.4
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14111
    
  16

Just specifying "-source 1.4" is not enough. That only tells the Java compiler that it should treat the source code as Java 1.4 source code, but the output will still be a Java 5.0 class file.

You will need to use the "-target 1.4" switch too. Note that this is not really safe - if your program uses classes or interfaces which are new in Java 5.0, then you will get ClassNotFoundErrors when you try to run the program on Java 1.4.

If your program needs to run under Java 1.4, then it's safest to use JDK 1.4 instead of using a newer JDK. You can download JDK 1.4 from Sun's website here.

If you absolutely want to use Java 5.0 and still make it run on Java 1.4, have a look at Retroweaver.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
ajay yaduwanshi
Greenhorn

Joined: Oct 12, 2007
Posts: 28
Thanks for your reply.
Actually I compiled my whole code(project) in netbean(windows) created a jar file of it .
created a shell script where I provide the class path all my jar file and then tried to execute.
Could you please help me wht to do to resolve the issue.
I appreciate your response, however I am not getting idea how to proceed with whole project..

Thanks & Regards

Ajay Singh Yaduwanshi
Jan van Mansum
Ranch Hand

Joined: Oct 19, 2007
Posts: 74
Actually the javac documentation says:

-target version
Generate class files that will work on VMs with the specified version. The default is to generate class files to be compatible with the JDK 5 VM. When the -source 1.4 or lower option is used, the default target is 1.4. The versions supported by javac are:


I am definitely going to check out Retroweaver, as I am indeed working on a project that needs to be compatible with 1.4.
Jan van Mansum
Ranch Hand

Joined: Oct 19, 2007
Posts: 74
Right-click your project in NetBeans, select Properties. Build->Compiling-Additional Compiler Options.

Type in -source=1.4 -target=1.4

Recompile. I think that should work.

To be on the safe side with the APIs, go to the Java Platform Manager under the Tools menu and add a 1.4.2 JDK as a java platform. The set this as your project's RT library.
ajay yaduwanshi
Greenhorn

Joined: Oct 12, 2007
Posts: 28
Thanks for your reply
I am just downloading jdk1.4 and try to implement wht you suggest to me,
I will let you know soon whether that works or not.

Once again thanks a lot for your valuable and clear suggetion.

Thanks & Regards

Ajay Singh Yaduwanshi
ajay yaduwanshi
Greenhorn

Joined: Oct 12, 2007
Posts: 28
Hey
I got a small issue, I downloaded java j2sdk1.4.2_16 installed it and in tools platform manager (netbean) option I have given the path of the newly installed java, however it is still taking the default java path.
after rgt clicking the project and compile option then in advance compile box option I put -source=1.4 -target=1.4 as said to me to do, However when I debug or build the project I am getting this message javac: invalid flag: -source=1.4
Usage: javac <options> <source files>

Please help me this.

Thanks & Regards

Ajay SIngh Yaduwanshi
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

Omit the = signs; it's just -source 1.4


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
ajay yaduwanshi
Greenhorn

Joined: Oct 12, 2007
Posts: 28
Dear friend I did as you said however now I am getting
javac: source release 1.5 requires target release 1.5

Although I put in addtional compile option target as 1.4.

Thanks for response dear

Best
Ajay singh Yaduwanshi
Jan van Mansum
Ranch Hand

Joined: Oct 19, 2007
Posts: 74
In your project in NetBeans, in the Projects view, under the node "Libraries" does it say JDK 1.4.2? If not, you must right-click on "Libraries". Select "Properties" and select the 1.4.2 Java Platform from the combo-box.

If that doesn't work, you should try asking further instructions at a NetBeans forum. There's probably someone there who knows. Good luck!
ajay yaduwanshi
Greenhorn

Joined: Oct 12, 2007
Posts: 28
Hi
Thanks for your response, Even after trying the way you said to me I am getting this message while trying to debug the project
Non-existing path "C:\j2sdk1.4.2_16\jre\lib\i18n.jar" provided.
Non-existing path "C:\j2sdk1.4.2_16\jre\classes" provided.
java.lang.UnsupportedClassVersionError: com/pbx/main/PBXMain (Unsupported major.minor version 49.0)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
Exception in thread "main"

Please help me with this.

Thanks & Regards

Ajay Singh Yaduwanshi
ajay yaduwanshi
Greenhorn

Joined: Oct 12, 2007
Posts: 28
Thanks Jan van Mansum, the issue get resolved.

Thank you very much..

Ajay Singh Yaduwanshi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception: java.lang.ClassVersionError: