Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 things. Steps I think of are: 1. Read the jar and get the entry with the name of class by using methods from java.util.jar package 2. Load this class, get the array from the class, change it 3. Maybe compile the code to apply the changes 4. Put the renewed class to the jar file

I dont know how to do 2nd and 3rd steps in java.

I was thinking to write new java class which extends this class and change the array, but this array is declared as public static final, thats why I cannot change it. Or I am wrong and there is a way of changing the array by extending the class?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
103 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...