1

I'm using Ant to compile Java.The project has to be compiled using JDK 1.5 , however some part of the code references a package compiled with JDK 1.6 version. I set the JAVA_HOME to 1.5 , error is thrown at this reference as

[javac] class file has wrong version 50.0, should be 49.0

What is the way out without downgrading the reference version to 1.5

asked Jun 23, 2011 at 7:42

3 Answers 3

4

What you are asking isn't possible. You should compile your library with JDK 1.5.

answered Jun 23, 2011 at 7:45
Sign up to request clarification or add additional context in comments.

Comments

1

Once Java has been compiled at a certain version, you cannot use that version on older versions of Java.

The package you are using might have a version available which is suitable for an older version of Java, alternatively you may be able to get the source code and recompile with the older version (if it doesn't use any Java 6 libraries / features).

answered Jun 23, 2011 at 7:50

2 Comments

The same is coimpiling without issues on NetBeans IDE. I require this to support commandline
@Pushparaj The same is coimpiling without issues on NetBeans IDE Are you sure NetBeans is using JDK 5?
0

Think this way:

The library you use has been compiled using JDK 6. It may be using some features introduced in Java 6 (that were not part of previous versions of Java)

When you use JDK 5 to compile and run, what do you expect the compiler (and the runtime) to do when this "new" feature is encountered? The JDK 5 does not know this feature and will be "confused"

To avoid this confusion at runtime, the compile itself fails.

You have two options:

  • Compile your project using JDK 6.
  • Get a JDK 5 compiled version of your library

If your project were using JDK 6 and the library was compiled with JDK 5, then you wouldn't have faced this issue because of backwards compatibility.

answered Jun 23, 2011 at 7:58

2 Comments

To be more specific the code just uses that jar which is of JDK 1.6 version.NetBeans compiles the project successfully when th Java level is set to 1.5
@Pushparaj The compiler you are using with NetBeans and the one you are using with ant - are they same?

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.