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?
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.
Extract -> Decompile -> Add code -> Create Jar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With