Changing the code of the class from jar file

后端 未结 3 1089
半阙折子戏
半阙折子戏 2021-01-03 06:49

How can I read (load) the java class from jar file, add some code to the class and then put back to the jar? I need to write a script (a java code) which does all these thin

相关标签:
3条回答
  • 2021-01-03 07:48

    A jar is just a ZIP file, so you can extract it with any archive manager like 7-ZIP. It will contain class files, which are compiled Java files. You need a Java decompiler to read and modify the bytecode.

    0 讨论(0)
  • 2021-01-03 07:51

    Extract -> Decompile -> Add code -> Create Jar

    0 讨论(0)
  • 2021-01-03 07:53

    The best solution would be to use the JAR in your code and extend the class (if the class allows you to do it).

    If you can't, the JAR class is actually a ZIP archive. You can rename x.jar to x.zip and extract the content:

    Here you have more informations (see especially OscarRyz's answer): How do you recompile a jar file?

    0 讨论(0)
提交回复
热议问题