Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decompile & recompile single file from jar

This problem has been solved witht he help of the comments:

It was necessary to recompile the java with the correct target version. In my case javac -source 1.3 -target 1.3 instead of simply javac did the trick.

Problem Description:

I have a compiled .jar java program in which a single url string needs to be modified. Using JD I was able to decompile the code and make the changes.

As I would like to avoid having to recompile the entire project I thought I could simply recompile the single .java file I modified into a .class and replace the original with it.

However, after repackaging the jar, the program does start but the functionality making use of the code I modified behaves erratically.

In the log I find:

E EventDispatchThreadExceptionHandler:Unhandled exception occurred during event dispatching.::
java.util.MissingResourceException: Can't find bundle for base name com.myCompany.mySoftware.resources.ModuleResources, locale en_US
       at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:842)

ModuleResources.java is the file I modified...

Analysis of the problem:

  1. Repackageing is not at fault: if I extract and repackage the original jar, everything works.
  2. My modification does equally not seem to be the problem: when I recompile the JD-decompiled java file and use the resulting class file for repackaging, I get the same failure.

I decompiled the repackaged jar file and compared it with the decompilation of the original jar file: In the file I modified (at least) the code seems to be identical BUT JD shows different line numbers. Could that hint at the problem?

Any help would be greatly appreciated.

Many thanks!

like image 732
ARF Avatar asked Dec 04 '25 16:12

ARF


1 Answers

This is the old question.

Nowadays, I found the good method to decompile and repack the jar file.

Here is the good document.

https://www.talksinfo.com/how-to-edit-class-file-from-a-jar/

I recommend the third method in the document.!!!

like image 122
Star_Man Avatar answered Dec 08 '25 21:12

Star_Man



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!