Updating .class file in jar

后端 未结 11 894
南笙
南笙 2020-11-27 05:52

I want to update a .class file in a jar with a new one. What is the easiest way to do it, especially in the Eclipse IDE?

11条回答
  •  借酒劲吻你
    2020-11-27 06:27

    A JAR file is just a .zip in disguise. The zipped folder contains .class files.

    If you're on macOS:

    1. Rename the file to possess the '.zip' extension. e.g. myJar.jar -> myJar.zip.
    2. Decompress the '.zip' (double click on it). A new folder called 'myJar' will appear
    3. Find and replace the .class file with your new .class file.
    4. Select all the contents of the folder 'myJar' and choose 'Compress x items'. DO NOT ZIP THE FOLDER ITSELF, ONLY ITS CONTENTS

    Miscellaneous - Compiling a single .class file, with reference to a original jar, on macOS

    1. Make a file myClass.java, containing your code.
    2. Open terminal from Spotlight.
    3. javac -classpath originalJar.jar myClass.java This will create your compiled class called myClass.class.

    From here, follow the steps above. You can also use Eclipse to compile it, simply reference the original jar by right clicking on the project, 'Build Path' -> 'Add External Archives'. From here you should be able to compile it as a jar, and use the zip technique above to retrieve the class from the jar.

提交回复
热议问题