Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception: java.lang.ClassVersionError:

 
ajay yaduwanshi
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Compile with -source=1.4
You won't be able to use class templates though.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15356
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
ajay yaduwanshi
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20546
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Omit the = signs; it's just -source 1.4
 
ajay yaduwanshi
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jan van Mansum, the issue get resolved.

Thank you very much..

Ajay Singh Yaduwanshi
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic