5

I'm working on a Java application, where I need to use a jar called myBeans.jar.

This myBeans.jar contains lots of class files, that are compiled with jdk 1.7. I don't have the source code for those class files.

And my whole application is using jdk 1.6. I can't change it's compiler to jdk 1.7. So I want my jar to be compatible with my app. And that's why I want the classes of the jar to be compiled with jdk 1.6.

Now my question is: Is there any way to compile the class files (& not java files) using jdk 1.6?

Any alternate suggestions are also welcome.

Someone recommended me to get the source code from class files using decompiler & then compile the source code with jdk 1.6. But I would prefer this solution at the last as there are lots of class files.

RAS
  • 8,100
  • 16
  • 64
  • 86
  • 1
    Have you checked if there is an older version of `MyBeans.jar` that was compiled with java 6? If it is a downloaded library they might have an archive. – Daniel Lerps Jul 04 '13 at 09:40
  • 3
    +1,but not possible I guess http://stackoverflow.com/questions/6699347/jdk-7-class-file-backward-compatibility-with-jdk-6 – Suresh Atta Jul 04 '13 at 09:40
  • @DanielLerps Yes I have checked but I'm not able to find the older jar. – RAS Jul 04 '13 at 09:42
  • 1
    .class files are already compiled. You compile .java files, not .class files. – user207421 Jul 04 '13 at 10:17
  • @EJP You should not edit any title if you're not clear about question. – RAS Jul 04 '13 at 10:27
  • @EJP I know I can compile java file & class file is already a compiled file. Read the question again & ask me what you didn't understand? – RAS Jul 04 '13 at 10:29
  • What I didn't understand is why you think you can compile .class files. You can't. It's a contradiction in terms. Not a real question. – user207421 Jul 04 '13 at 10:40
  • @EJP, there you got the question. I know I can't compile a class file directly. I asked the question because there may be some online tools or plugins or some other way out so that I can get the class files of the jar to be compiled with jdk 1.6 without the source code. – RAS Jul 04 '13 at 10:45
  • 1
    The original title was poor and described a possible solution, not the problem in hand. Hopefully my edit makes it easier to see what this question is about. – Duncan Jones Jul 04 '13 at 14:18
  • @DuncanJones Ok thanks for the improvement. – RAS Jul 05 '13 at 06:30

1 Answers1

3

This will probably not work. Java 7 has introduced language features not present in earlier versions, so if any of these have been used in the library you may not be able to recompile using JDK 6.

Also, new methods and classes are introduced with each Java revision, so if any @since 1.7 items are used in the library, they will not be present in your Java 6 environment and the build will fail.

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
  • Any online tool or plugin or something..? – RAS Jul 04 '13 at 09:45
  • @RAS I don't know of an approach to take other than the manual decompile/recompile suggested by your acquaintance. – Duncan Jones Jul 04 '13 at 09:45
  • I want my jar to be compatible with my app. App is compiled using jdk 1.7 & jar is compiled using jdk 1.6. I can't change app compilation to be jdk 1.7. – RAS Jul 04 '13 at 09:47