0

I have a .jar file from 2008 for a work project which I must edit and then repack into a .jar. I'm importing the .jar into Eclipse in order to make modifications but the classes use code such as "new Integer(true)" and "HttpServletRequest" which, from my understanding, is no longer valid code so I get a hundreds of errors when I try to build.

What can I do to have Eclipse recognize this as valid code and run the project?

  • 2
    In general, Java code will not break syntactically from version to version (especially "hundreds of errors" in a project). `HttpServletRequest` is valid code but it requires a specific set of libraries in the environment (i.e. a servlet runtime). Have you made sure to take this into account? – nanofarad Jul 02 '19 at 20:38
  • 1
    Do yu actually have the source files or are you decompiling the classes in the jar-file? – Turing85 Jul 02 '19 at 20:49
  • I don't have the source files, no one can find them. What I have is the .jar file we run of the program. I used JD-GUI to decompile the classes of the .jar file and then was importing them into the src folder of my Eclipse project – Robert Heras Jul 02 '19 at 22:41

1 Answers1

0

You need to include all the libraries that jar needs to run. To start that will probably be java 6. https://en.wikipedia.org/wiki/Java_version_history

Say that jar is from 2008, and runs on java 6. Then you might wish to install a java 6 development enviroment. Then if there are libraries missing, see if you can download versions of those libraries from 2008, or check the original jar system where you got it from if they are downloaded there somewhere and add them as libraries in eclipse.

Also set your project > java compiler > enable project specific settings to the correct java version.

Also, keep in mind that compilers can and will make errors. Variables may be duplicated and such. This is an error I see a lot in compilers:

List var1 = something.getFoos();
Foo var2 = null;
for(int var2 = 0; var2 < length; var2++) {
    var2 = (Foo)var1.get(var2);
}

The new Integer(true) can also be a decompiler error, where it should have been new Integer(1);

Working from decompiled code is hard, and you have to double check everything and try to find out the logic and expected values from the program flow.

Tschallacka
  • 27,901
  • 14
  • 88
  • 133
  • Tomorrow I will try installing Java 6 and any other libraries it might need – Robert Heras Jul 02 '19 at 22:42
  • 1
    Before doing so, I advise you to look at the "magic number" of the byte code: this is what give the version of Java it was compiled with. While assertion of "2008 = Java 6" may be true, there was a lot of code that was _still_ in Java 4 or 5 due to lack of maintenance. The `file` command on Linux may help you: https://stackoverflow.com/questions/1293308/java-api-to-find-out-the-jdk-version-a-class-file-is-compiled-for – NoDataFound Jul 03 '19 at 08:52