Decompile & recompile single file from jar

三世轮回 提交于 2020-01-23 01:53:49

问题


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!


回答1:


when I recompile the JD-decompiled java file and use the resulting class file for repackaging, I get the same failure

This seems to point the finger at JD. When you recompile the JD-decompiled java file, can you compare the result with the original .class file (for example, by disassembling both and comparing the result)? If they differ in substance, that'll lend credence to the theory that JD is at fault; if they don't, then the problem lies elsewhere.




回答2:


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.!!!



来源:https://stackoverflow.com/questions/9583370/decompile-recompile-single-file-from-jar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!