![]() ![]() In my specific case, to make things as easy as possible, I wanted to only modify one. jar file completely recompiled and working with my application, I wanted to share here the steps that were missing in the previous answers. is it a so-called "executable" JAR that you launch using java -jar my.jar. It depends on what kind of JAR it is e.g. The (new) dependencies of the JAR don't necessarily need to be in the JAR itself. I guess that I have to add the libraries, but there is no extra lib directory. Therefore, when you make your changes and recompile, the resulting ".class" file could have unexpected / unwanted differences relative to the original. There is no guarantee that the Java code that it produces is a correct representation of the original class. unless you have the private key that was used when signing.ĭecompilation is often inaccurate. If the original JAR file was signed, you won't be able to re-sign the new JAR. You can do it using the command line jar tool see How to create a JAR file from the official Oracle Java tutorials.īut it there is no guarantee that what you are doing will actually work.You can do it using a build tool such as Maven, Gradle, Ant and so on.This will only work if your changes didn't have any side effects. You can then extract only the class files which you wanted to modify from the jar, and overwrite them in the original jar. In this case, instead of going through all available decompilers and hoping that you can decompile that code, I suggest you identify the set of classes which you are trying to edit, modify the rest of the classes such that they compile and do not have any side effects on the classes which are of interest to you (do not delete anything that is referenced by these) and compile the jar (even if this isn't the jar you want). If decompilation fails on some parts of the code, the functionality of the jar will not be restored upon recompilation. Once you have identified all the dependencies, you can easily compile the jar from an IDE such as IntelliJ/ Eclipse or from command line.Īs a side note, if the changes you would like to make to the jar are minor or isolated I recommend editing the bytecode (much easier for small edits). ![]() See this answer for details on how to achieve this. Check if there are any relationships with other jar files on the classpath when you run the original jar. When you create a jar, you can choose not to include dependencies in it, but this assumes that they will be available on the classpath at runtime. If you are missing dependencies after decompiling the entire jar, that could mean the jar did not include them. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |