1

I have a JAR someone else made and compiled with JDK 7 without source code that I want to recompile using JDK 6. The reason is that I only have JRE 6, so I can't run the JAR.

I know Java Decompiler can decompile the class files and export the source, which I can then compile, but it gets messy that way. Also, I tried it, and there are a bunch of syntax errors that JD probably caused. Is there a tool that'll just take a JAR and output a recompiled JAR? Mac is preferable, but I can run Linux or Windows.

sudo
  • 5,604
  • 5
  • 40
  • 78
  • The short answer would be no. The long answer would, well, you've already answered that ;) – MadProgrammer Mar 26 '14 at 23:47
  • I feel like I'm misunderstanding something really basic about Java… if this was compiled in JDK 7 but only used old libraries, would it still run in JRE 6? As it turns out, the code actually uses some Java 7 libraries, so there's no way to recompile this specific code. – sudo Mar 26 '14 at 23:49
  • 1
    No. If it was compiled with Java 7 and was not flagged to be compiled to be compatible with Java 6 (when it was compiled), it will incompatible, as the class version will be different. – MadProgrammer Mar 26 '14 at 23:53
  • 1
    possible duplicate of [Is JDK "upward" or "backward" compatible?](http://stackoverflow.com/questions/4692626/is-jdk-upward-or-backward-compatible) – mellamokb Mar 26 '14 at 23:53
  • The only two options are to decompile/recompile the code or to use hex editor to change the version number in the .class files. Both are very iffy and will fail much of the time. And of course neither will fix things if the code is referencing classes only available in the 7 JDK. (Well, actually there is a 3rd option, which is to install a 7 JRE.) – Hot Licks Mar 27 '14 at 00:03
  • OK, so according to MadProgrammer, Hot Licks, and the post mellamokb linked, it's theoretically possible… but anyway it's impossible in my case since the jar actually uses Java 7 libraries that aren't in 6. – sudo Mar 27 '14 at 00:12
  • Why can't you use JRE 7? – mellamokb Mar 27 '14 at 00:14
  • @mellamokb Long story short, the JRE itself keeps giving me fatal errors. Only v6 works. – sudo Mar 27 '14 at 00:25

1 Answers1

1

There are tools out there, but they all come with strings attached. Unfortunately I am not aware of any that will backport from 7 to 6 so the answer is probably NO.

See also: http://en.wikipedia.org/wiki/Java_backporting_tools

anttix
  • 7,709
  • 1
  • 24
  • 25