Updating .class file in jar












43















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?










share|improve this question




















  • 3





    Have you tried jar --help

    – Alexander Pogrebnyak
    Nov 3 '09 at 12:58
















43















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?










share|improve this question




















  • 3





    Have you tried jar --help

    – Alexander Pogrebnyak
    Nov 3 '09 at 12:58














43












43








43


7






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?










share|improve this question
















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?







java eclipse jar






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 13 '16 at 20:32









Einar Sundgren

2,46672951




2,46672951










asked Nov 3 '09 at 12:51









pengurupenguru

1,789113655




1,789113655








  • 3





    Have you tried jar --help

    – Alexander Pogrebnyak
    Nov 3 '09 at 12:58














  • 3





    Have you tried jar --help

    – Alexander Pogrebnyak
    Nov 3 '09 at 12:58








3




3





Have you tried jar --help

– Alexander Pogrebnyak
Nov 3 '09 at 12:58





Have you tried jar --help

– Alexander Pogrebnyak
Nov 3 '09 at 12:58












11 Answers
11






active

oldest

votes


















61














This tutorial details how to update a jar file



jar uf jar-file input-file(s)


where 'u' means update.






share|improve this answer



















  • 3





    In this command: The u option indicates that you want to update an existing JAR file. The f option indicates that the JAR file to update is specified on the command line. jar-file is the existing JAR file that's to be updated. input-file(s) is a space-delimited list of one or more files that you want to add to the Jar file.

    – Nishantha
    Jun 21 '13 at 6:43








  • 1





    I want to update a property file to a specific location, ideally there should be two parameters source and destination. For me input-file(s), but where is source?

    – Shashi Ranjan
    Jul 13 '17 at 7:40











  • @ShashiRanjan did you found the solution??

    – Dinesh Phalwadiya
    Dec 22 '17 at 4:56






  • 2





    @Dinesh I used "zip -u /var/opt/my-jar-with-dependencies.jar properties/my_app.properties". Basically "zip -u <source> <dest>", where dest is relative to the jar extract folder.

    – Shashi Ranjan
    Dec 22 '17 at 10:00











  • Thanks a lot @ShashiRanjan

    – Dinesh Phalwadiya
    Dec 22 '17 at 11:23



















11














Do you want to do it automatically or manually? If manually, a JAR file is really just a ZIP file, so you should be able to open it with any ZIP reader. (You may need to change the extension first.) If you want to update the JAR file automatically via Eclipse, you may want to look into Ant support in Eclipse and look at the zip task.






share|improve this answer

































    10














    Simply drag and drop your new class file to the JAR using 7-Zip or Winzip. You can even modify a JAR file that is included in a WAR file using the parent folder icon, and click Ok when 7zip detects that the inside file has been modified






    share|improve this answer
























    • Using WinZip, you have to open it by first starting WinZip, then drag the jar file into the WinZip window.

      – awe
      Apr 9 '10 at 6:17






    • 1





      7z on Windows does not respect upper/lower case, i.e. it would replace both CA.class and Ca.class

      – Anton Duzenko
      Apr 6 '16 at 11:04





















    6














    Jar is an archive, you can replace a file in it by yourself in your favourite file manager (Total Commander for example).






    share|improve this answer































      6















      1. Use jar -xvf to extract the files to a directory.

      2. Make your changes and replace the classes.

      3. Use jar -cvf to create a new jar file.






      share|improve this answer































        2














        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.






        share|improve this answer

































          0














          1) you can extract the file into a folder called




          jarname.jar




          and then replace the file in the folder, handy if you are updating the class a lot while debugging



          2) you can extract the jar replace the file then the jar it up again



          3) Open the jar with 7 zip and drag and drop your new class in to copy over the old one






          share|improve this answer































            0














            Editing properties/my_app.properties file inside jar:



            "zip -u /var/opt/my-jar-with-dependencies.jar properties/my_app.properties". Basically "zip -u <source> <dest>", where dest is relative to the jar extract folder.






            share|improve this answer































              0














              You can find source code of any .jar file online, import the same project in your IDE with basic setups. Make necessary changes in .java file and compile it for .class files.



              Once compilation is done You need to extract the jar file, replace the old .class file with new one.



              And use below command for reconstruct .jar file



              Jar cf test.jar *



              Note : I have done so many time this changes in our project, hope you will find it useful.






              share|improve this answer































                0














                High-level steps:



                Setup the environment
                Use JD-GUI to peek into the JAR file
                Unpack the JAR file
                Modify the .class file with a Java Bytecode Editor
                Update the modified classes into existing JAR file
                Verify it with JD-GUI


                Refer below link for detailed steps and methods to do it,



                https://www.talksinfo.com/how-to-edit-class-file-from-a-jar/






                share|improve this answer































                  -1














                  An alternative is not to replace the .class file in the jar file. Instead put it into a new jar file and ensure that it appears earlier on your classpath than the original jar file.



                  Not sure I would recommend this for production software but for development it is quick and easy.






                  share|improve this answer























                    Your Answer






                    StackExchange.ifUsing("editor", function () {
                    StackExchange.using("externalEditor", function () {
                    StackExchange.using("snippets", function () {
                    StackExchange.snippets.init();
                    });
                    });
                    }, "code-snippets");

                    StackExchange.ready(function() {
                    var channelOptions = {
                    tags: "".split(" "),
                    id: "1"
                    };
                    initTagRenderer("".split(" "), "".split(" "), channelOptions);

                    StackExchange.using("externalEditor", function() {
                    // Have to fire editor after snippets, if snippets enabled
                    if (StackExchange.settings.snippets.snippetsEnabled) {
                    StackExchange.using("snippets", function() {
                    createEditor();
                    });
                    }
                    else {
                    createEditor();
                    }
                    });

                    function createEditor() {
                    StackExchange.prepareEditor({
                    heartbeatType: 'answer',
                    autoActivateHeartbeat: false,
                    convertImagesToLinks: true,
                    noModals: true,
                    showLowRepImageUploadWarning: true,
                    reputationToPostImages: 10,
                    bindNavPrevention: true,
                    postfix: "",
                    imageUploader: {
                    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                    allowUrls: true
                    },
                    onDemand: true,
                    discardSelector: ".discard-answer"
                    ,immediatelyShowMarkdownHelp:true
                    });


                    }
                    });














                    draft saved

                    draft discarded


















                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f1667153%2fupdating-class-file-in-jar%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown

























                    11 Answers
                    11






                    active

                    oldest

                    votes








                    11 Answers
                    11






                    active

                    oldest

                    votes









                    active

                    oldest

                    votes






                    active

                    oldest

                    votes









                    61














                    This tutorial details how to update a jar file



                    jar uf jar-file input-file(s)


                    where 'u' means update.






                    share|improve this answer



















                    • 3





                      In this command: The u option indicates that you want to update an existing JAR file. The f option indicates that the JAR file to update is specified on the command line. jar-file is the existing JAR file that's to be updated. input-file(s) is a space-delimited list of one or more files that you want to add to the Jar file.

                      – Nishantha
                      Jun 21 '13 at 6:43








                    • 1





                      I want to update a property file to a specific location, ideally there should be two parameters source and destination. For me input-file(s), but where is source?

                      – Shashi Ranjan
                      Jul 13 '17 at 7:40











                    • @ShashiRanjan did you found the solution??

                      – Dinesh Phalwadiya
                      Dec 22 '17 at 4:56






                    • 2





                      @Dinesh I used "zip -u /var/opt/my-jar-with-dependencies.jar properties/my_app.properties". Basically "zip -u <source> <dest>", where dest is relative to the jar extract folder.

                      – Shashi Ranjan
                      Dec 22 '17 at 10:00











                    • Thanks a lot @ShashiRanjan

                      – Dinesh Phalwadiya
                      Dec 22 '17 at 11:23
















                    61














                    This tutorial details how to update a jar file



                    jar uf jar-file input-file(s)


                    where 'u' means update.






                    share|improve this answer



















                    • 3





                      In this command: The u option indicates that you want to update an existing JAR file. The f option indicates that the JAR file to update is specified on the command line. jar-file is the existing JAR file that's to be updated. input-file(s) is a space-delimited list of one or more files that you want to add to the Jar file.

                      – Nishantha
                      Jun 21 '13 at 6:43








                    • 1





                      I want to update a property file to a specific location, ideally there should be two parameters source and destination. For me input-file(s), but where is source?

                      – Shashi Ranjan
                      Jul 13 '17 at 7:40











                    • @ShashiRanjan did you found the solution??

                      – Dinesh Phalwadiya
                      Dec 22 '17 at 4:56






                    • 2





                      @Dinesh I used "zip -u /var/opt/my-jar-with-dependencies.jar properties/my_app.properties". Basically "zip -u <source> <dest>", where dest is relative to the jar extract folder.

                      – Shashi Ranjan
                      Dec 22 '17 at 10:00











                    • Thanks a lot @ShashiRanjan

                      – Dinesh Phalwadiya
                      Dec 22 '17 at 11:23














                    61












                    61








                    61







                    This tutorial details how to update a jar file



                    jar uf jar-file input-file(s)


                    where 'u' means update.






                    share|improve this answer













                    This tutorial details how to update a jar file



                    jar uf jar-file input-file(s)


                    where 'u' means update.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 3 '09 at 13:14









                    Brian AgnewBrian Agnew

                    229k32281395




                    229k32281395








                    • 3





                      In this command: The u option indicates that you want to update an existing JAR file. The f option indicates that the JAR file to update is specified on the command line. jar-file is the existing JAR file that's to be updated. input-file(s) is a space-delimited list of one or more files that you want to add to the Jar file.

                      – Nishantha
                      Jun 21 '13 at 6:43








                    • 1





                      I want to update a property file to a specific location, ideally there should be two parameters source and destination. For me input-file(s), but where is source?

                      – Shashi Ranjan
                      Jul 13 '17 at 7:40











                    • @ShashiRanjan did you found the solution??

                      – Dinesh Phalwadiya
                      Dec 22 '17 at 4:56






                    • 2





                      @Dinesh I used "zip -u /var/opt/my-jar-with-dependencies.jar properties/my_app.properties". Basically "zip -u <source> <dest>", where dest is relative to the jar extract folder.

                      – Shashi Ranjan
                      Dec 22 '17 at 10:00











                    • Thanks a lot @ShashiRanjan

                      – Dinesh Phalwadiya
                      Dec 22 '17 at 11:23














                    • 3





                      In this command: The u option indicates that you want to update an existing JAR file. The f option indicates that the JAR file to update is specified on the command line. jar-file is the existing JAR file that's to be updated. input-file(s) is a space-delimited list of one or more files that you want to add to the Jar file.

                      – Nishantha
                      Jun 21 '13 at 6:43








                    • 1





                      I want to update a property file to a specific location, ideally there should be two parameters source and destination. For me input-file(s), but where is source?

                      – Shashi Ranjan
                      Jul 13 '17 at 7:40











                    • @ShashiRanjan did you found the solution??

                      – Dinesh Phalwadiya
                      Dec 22 '17 at 4:56






                    • 2





                      @Dinesh I used "zip -u /var/opt/my-jar-with-dependencies.jar properties/my_app.properties". Basically "zip -u <source> <dest>", where dest is relative to the jar extract folder.

                      – Shashi Ranjan
                      Dec 22 '17 at 10:00











                    • Thanks a lot @ShashiRanjan

                      – Dinesh Phalwadiya
                      Dec 22 '17 at 11:23








                    3




                    3





                    In this command: The u option indicates that you want to update an existing JAR file. The f option indicates that the JAR file to update is specified on the command line. jar-file is the existing JAR file that's to be updated. input-file(s) is a space-delimited list of one or more files that you want to add to the Jar file.

                    – Nishantha
                    Jun 21 '13 at 6:43







                    In this command: The u option indicates that you want to update an existing JAR file. The f option indicates that the JAR file to update is specified on the command line. jar-file is the existing JAR file that's to be updated. input-file(s) is a space-delimited list of one or more files that you want to add to the Jar file.

                    – Nishantha
                    Jun 21 '13 at 6:43






                    1




                    1





                    I want to update a property file to a specific location, ideally there should be two parameters source and destination. For me input-file(s), but where is source?

                    – Shashi Ranjan
                    Jul 13 '17 at 7:40





                    I want to update a property file to a specific location, ideally there should be two parameters source and destination. For me input-file(s), but where is source?

                    – Shashi Ranjan
                    Jul 13 '17 at 7:40













                    @ShashiRanjan did you found the solution??

                    – Dinesh Phalwadiya
                    Dec 22 '17 at 4:56





                    @ShashiRanjan did you found the solution??

                    – Dinesh Phalwadiya
                    Dec 22 '17 at 4:56




                    2




                    2





                    @Dinesh I used "zip -u /var/opt/my-jar-with-dependencies.jar properties/my_app.properties". Basically "zip -u <source> <dest>", where dest is relative to the jar extract folder.

                    – Shashi Ranjan
                    Dec 22 '17 at 10:00





                    @Dinesh I used "zip -u /var/opt/my-jar-with-dependencies.jar properties/my_app.properties". Basically "zip -u <source> <dest>", where dest is relative to the jar extract folder.

                    – Shashi Ranjan
                    Dec 22 '17 at 10:00













                    Thanks a lot @ShashiRanjan

                    – Dinesh Phalwadiya
                    Dec 22 '17 at 11:23





                    Thanks a lot @ShashiRanjan

                    – Dinesh Phalwadiya
                    Dec 22 '17 at 11:23













                    11














                    Do you want to do it automatically or manually? If manually, a JAR file is really just a ZIP file, so you should be able to open it with any ZIP reader. (You may need to change the extension first.) If you want to update the JAR file automatically via Eclipse, you may want to look into Ant support in Eclipse and look at the zip task.






                    share|improve this answer






























                      11














                      Do you want to do it automatically or manually? If manually, a JAR file is really just a ZIP file, so you should be able to open it with any ZIP reader. (You may need to change the extension first.) If you want to update the JAR file automatically via Eclipse, you may want to look into Ant support in Eclipse and look at the zip task.






                      share|improve this answer




























                        11












                        11








                        11







                        Do you want to do it automatically or manually? If manually, a JAR file is really just a ZIP file, so you should be able to open it with any ZIP reader. (You may need to change the extension first.) If you want to update the JAR file automatically via Eclipse, you may want to look into Ant support in Eclipse and look at the zip task.






                        share|improve this answer















                        Do you want to do it automatically or manually? If manually, a JAR file is really just a ZIP file, so you should be able to open it with any ZIP reader. (You may need to change the extension first.) If you want to update the JAR file automatically via Eclipse, you may want to look into Ant support in Eclipse and look at the zip task.







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Jan 23 '11 at 23:53









                        martin clayton

                        66k18187181




                        66k18187181










                        answered Nov 3 '09 at 12:54









                        JasCavJasCav

                        25.9k1897152




                        25.9k1897152























                            10














                            Simply drag and drop your new class file to the JAR using 7-Zip or Winzip. You can even modify a JAR file that is included in a WAR file using the parent folder icon, and click Ok when 7zip detects that the inside file has been modified






                            share|improve this answer
























                            • Using WinZip, you have to open it by first starting WinZip, then drag the jar file into the WinZip window.

                              – awe
                              Apr 9 '10 at 6:17






                            • 1





                              7z on Windows does not respect upper/lower case, i.e. it would replace both CA.class and Ca.class

                              – Anton Duzenko
                              Apr 6 '16 at 11:04


















                            10














                            Simply drag and drop your new class file to the JAR using 7-Zip or Winzip. You can even modify a JAR file that is included in a WAR file using the parent folder icon, and click Ok when 7zip detects that the inside file has been modified






                            share|improve this answer
























                            • Using WinZip, you have to open it by first starting WinZip, then drag the jar file into the WinZip window.

                              – awe
                              Apr 9 '10 at 6:17






                            • 1





                              7z on Windows does not respect upper/lower case, i.e. it would replace both CA.class and Ca.class

                              – Anton Duzenko
                              Apr 6 '16 at 11:04
















                            10












                            10








                            10







                            Simply drag and drop your new class file to the JAR using 7-Zip or Winzip. You can even modify a JAR file that is included in a WAR file using the parent folder icon, and click Ok when 7zip detects that the inside file has been modified






                            share|improve this answer













                            Simply drag and drop your new class file to the JAR using 7-Zip or Winzip. You can even modify a JAR file that is included in a WAR file using the parent folder icon, and click Ok when 7zip detects that the inside file has been modified







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 3 '09 at 13:47









                            LastnicoLastnico

                            1,3011013




                            1,3011013













                            • Using WinZip, you have to open it by first starting WinZip, then drag the jar file into the WinZip window.

                              – awe
                              Apr 9 '10 at 6:17






                            • 1





                              7z on Windows does not respect upper/lower case, i.e. it would replace both CA.class and Ca.class

                              – Anton Duzenko
                              Apr 6 '16 at 11:04





















                            • Using WinZip, you have to open it by first starting WinZip, then drag the jar file into the WinZip window.

                              – awe
                              Apr 9 '10 at 6:17






                            • 1





                              7z on Windows does not respect upper/lower case, i.e. it would replace both CA.class and Ca.class

                              – Anton Duzenko
                              Apr 6 '16 at 11:04



















                            Using WinZip, you have to open it by first starting WinZip, then drag the jar file into the WinZip window.

                            – awe
                            Apr 9 '10 at 6:17





                            Using WinZip, you have to open it by first starting WinZip, then drag the jar file into the WinZip window.

                            – awe
                            Apr 9 '10 at 6:17




                            1




                            1





                            7z on Windows does not respect upper/lower case, i.e. it would replace both CA.class and Ca.class

                            – Anton Duzenko
                            Apr 6 '16 at 11:04







                            7z on Windows does not respect upper/lower case, i.e. it would replace both CA.class and Ca.class

                            – Anton Duzenko
                            Apr 6 '16 at 11:04













                            6














                            Jar is an archive, you can replace a file in it by yourself in your favourite file manager (Total Commander for example).






                            share|improve this answer




























                              6














                              Jar is an archive, you can replace a file in it by yourself in your favourite file manager (Total Commander for example).






                              share|improve this answer


























                                6












                                6








                                6







                                Jar is an archive, you can replace a file in it by yourself in your favourite file manager (Total Commander for example).






                                share|improve this answer













                                Jar is an archive, you can replace a file in it by yourself in your favourite file manager (Total Commander for example).







                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Nov 3 '09 at 12:55









                                silentsilent

                                2,9801729




                                2,9801729























                                    6















                                    1. Use jar -xvf to extract the files to a directory.

                                    2. Make your changes and replace the classes.

                                    3. Use jar -cvf to create a new jar file.






                                    share|improve this answer




























                                      6















                                      1. Use jar -xvf to extract the files to a directory.

                                      2. Make your changes and replace the classes.

                                      3. Use jar -cvf to create a new jar file.






                                      share|improve this answer


























                                        6












                                        6








                                        6








                                        1. Use jar -xvf to extract the files to a directory.

                                        2. Make your changes and replace the classes.

                                        3. Use jar -cvf to create a new jar file.






                                        share|improve this answer














                                        1. Use jar -xvf to extract the files to a directory.

                                        2. Make your changes and replace the classes.

                                        3. Use jar -cvf to create a new jar file.







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Oct 21 '14 at 19:23









                                        James LimJames Lim

                                        10.7k33057




                                        10.7k33057























                                            2














                                            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.






                                            share|improve this answer






























                                              2














                                              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.






                                              share|improve this answer




























                                                2












                                                2








                                                2







                                                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.






                                                share|improve this answer















                                                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.







                                                share|improve this answer














                                                share|improve this answer



                                                share|improve this answer








                                                edited Jun 4 '17 at 5:00

























                                                answered Sep 12 '16 at 20:42









                                                Toby MellorToby Mellor

                                                5,77851946




                                                5,77851946























                                                    0














                                                    1) you can extract the file into a folder called




                                                    jarname.jar




                                                    and then replace the file in the folder, handy if you are updating the class a lot while debugging



                                                    2) you can extract the jar replace the file then the jar it up again



                                                    3) Open the jar with 7 zip and drag and drop your new class in to copy over the old one






                                                    share|improve this answer




























                                                      0














                                                      1) you can extract the file into a folder called




                                                      jarname.jar




                                                      and then replace the file in the folder, handy if you are updating the class a lot while debugging



                                                      2) you can extract the jar replace the file then the jar it up again



                                                      3) Open the jar with 7 zip and drag and drop your new class in to copy over the old one






                                                      share|improve this answer


























                                                        0












                                                        0








                                                        0







                                                        1) you can extract the file into a folder called




                                                        jarname.jar




                                                        and then replace the file in the folder, handy if you are updating the class a lot while debugging



                                                        2) you can extract the jar replace the file then the jar it up again



                                                        3) Open the jar with 7 zip and drag and drop your new class in to copy over the old one






                                                        share|improve this answer













                                                        1) you can extract the file into a folder called




                                                        jarname.jar




                                                        and then replace the file in the folder, handy if you are updating the class a lot while debugging



                                                        2) you can extract the jar replace the file then the jar it up again



                                                        3) Open the jar with 7 zip and drag and drop your new class in to copy over the old one







                                                        share|improve this answer












                                                        share|improve this answer



                                                        share|improve this answer










                                                        answered Nov 3 '09 at 13:19









                                                        Craig AngusCraig Angus

                                                        11.4k155161




                                                        11.4k155161























                                                            0














                                                            Editing properties/my_app.properties file inside jar:



                                                            "zip -u /var/opt/my-jar-with-dependencies.jar properties/my_app.properties". Basically "zip -u <source> <dest>", where dest is relative to the jar extract folder.






                                                            share|improve this answer




























                                                              0














                                                              Editing properties/my_app.properties file inside jar:



                                                              "zip -u /var/opt/my-jar-with-dependencies.jar properties/my_app.properties". Basically "zip -u <source> <dest>", where dest is relative to the jar extract folder.






                                                              share|improve this answer


























                                                                0












                                                                0








                                                                0







                                                                Editing properties/my_app.properties file inside jar:



                                                                "zip -u /var/opt/my-jar-with-dependencies.jar properties/my_app.properties". Basically "zip -u <source> <dest>", where dest is relative to the jar extract folder.






                                                                share|improve this answer













                                                                Editing properties/my_app.properties file inside jar:



                                                                "zip -u /var/opt/my-jar-with-dependencies.jar properties/my_app.properties". Basically "zip -u <source> <dest>", where dest is relative to the jar extract folder.







                                                                share|improve this answer












                                                                share|improve this answer



                                                                share|improve this answer










                                                                answered Dec 22 '17 at 10:03









                                                                Shashi RanjanShashi Ranjan

                                                                69221226




                                                                69221226























                                                                    0














                                                                    You can find source code of any .jar file online, import the same project in your IDE with basic setups. Make necessary changes in .java file and compile it for .class files.



                                                                    Once compilation is done You need to extract the jar file, replace the old .class file with new one.



                                                                    And use below command for reconstruct .jar file



                                                                    Jar cf test.jar *



                                                                    Note : I have done so many time this changes in our project, hope you will find it useful.






                                                                    share|improve this answer




























                                                                      0














                                                                      You can find source code of any .jar file online, import the same project in your IDE with basic setups. Make necessary changes in .java file and compile it for .class files.



                                                                      Once compilation is done You need to extract the jar file, replace the old .class file with new one.



                                                                      And use below command for reconstruct .jar file



                                                                      Jar cf test.jar *



                                                                      Note : I have done so many time this changes in our project, hope you will find it useful.






                                                                      share|improve this answer


























                                                                        0












                                                                        0








                                                                        0







                                                                        You can find source code of any .jar file online, import the same project in your IDE with basic setups. Make necessary changes in .java file and compile it for .class files.



                                                                        Once compilation is done You need to extract the jar file, replace the old .class file with new one.



                                                                        And use below command for reconstruct .jar file



                                                                        Jar cf test.jar *



                                                                        Note : I have done so many time this changes in our project, hope you will find it useful.






                                                                        share|improve this answer













                                                                        You can find source code of any .jar file online, import the same project in your IDE with basic setups. Make necessary changes in .java file and compile it for .class files.



                                                                        Once compilation is done You need to extract the jar file, replace the old .class file with new one.



                                                                        And use below command for reconstruct .jar file



                                                                        Jar cf test.jar *



                                                                        Note : I have done so many time this changes in our project, hope you will find it useful.







                                                                        share|improve this answer












                                                                        share|improve this answer



                                                                        share|improve this answer










                                                                        answered Mar 22 '18 at 10:07









                                                                        harihari

                                                                        337




                                                                        337























                                                                            0














                                                                            High-level steps:



                                                                            Setup the environment
                                                                            Use JD-GUI to peek into the JAR file
                                                                            Unpack the JAR file
                                                                            Modify the .class file with a Java Bytecode Editor
                                                                            Update the modified classes into existing JAR file
                                                                            Verify it with JD-GUI


                                                                            Refer below link for detailed steps and methods to do it,



                                                                            https://www.talksinfo.com/how-to-edit-class-file-from-a-jar/






                                                                            share|improve this answer




























                                                                              0














                                                                              High-level steps:



                                                                              Setup the environment
                                                                              Use JD-GUI to peek into the JAR file
                                                                              Unpack the JAR file
                                                                              Modify the .class file with a Java Bytecode Editor
                                                                              Update the modified classes into existing JAR file
                                                                              Verify it with JD-GUI


                                                                              Refer below link for detailed steps and methods to do it,



                                                                              https://www.talksinfo.com/how-to-edit-class-file-from-a-jar/






                                                                              share|improve this answer


























                                                                                0












                                                                                0








                                                                                0







                                                                                High-level steps:



                                                                                Setup the environment
                                                                                Use JD-GUI to peek into the JAR file
                                                                                Unpack the JAR file
                                                                                Modify the .class file with a Java Bytecode Editor
                                                                                Update the modified classes into existing JAR file
                                                                                Verify it with JD-GUI


                                                                                Refer below link for detailed steps and methods to do it,



                                                                                https://www.talksinfo.com/how-to-edit-class-file-from-a-jar/






                                                                                share|improve this answer













                                                                                High-level steps:



                                                                                Setup the environment
                                                                                Use JD-GUI to peek into the JAR file
                                                                                Unpack the JAR file
                                                                                Modify the .class file with a Java Bytecode Editor
                                                                                Update the modified classes into existing JAR file
                                                                                Verify it with JD-GUI


                                                                                Refer below link for detailed steps and methods to do it,



                                                                                https://www.talksinfo.com/how-to-edit-class-file-from-a-jar/







                                                                                share|improve this answer












                                                                                share|improve this answer



                                                                                share|improve this answer










                                                                                answered Nov 25 '18 at 20:47









                                                                                user2266614user2266614

                                                                                13




                                                                                13























                                                                                    -1














                                                                                    An alternative is not to replace the .class file in the jar file. Instead put it into a new jar file and ensure that it appears earlier on your classpath than the original jar file.



                                                                                    Not sure I would recommend this for production software but for development it is quick and easy.






                                                                                    share|improve this answer




























                                                                                      -1














                                                                                      An alternative is not to replace the .class file in the jar file. Instead put it into a new jar file and ensure that it appears earlier on your classpath than the original jar file.



                                                                                      Not sure I would recommend this for production software but for development it is quick and easy.






                                                                                      share|improve this answer


























                                                                                        -1












                                                                                        -1








                                                                                        -1







                                                                                        An alternative is not to replace the .class file in the jar file. Instead put it into a new jar file and ensure that it appears earlier on your classpath than the original jar file.



                                                                                        Not sure I would recommend this for production software but for development it is quick and easy.






                                                                                        share|improve this answer













                                                                                        An alternative is not to replace the .class file in the jar file. Instead put it into a new jar file and ensure that it appears earlier on your classpath than the original jar file.



                                                                                        Not sure I would recommend this for production software but for development it is quick and easy.







                                                                                        share|improve this answer












                                                                                        share|improve this answer



                                                                                        share|improve this answer










                                                                                        answered Nov 3 '09 at 13:56









                                                                                        Dave JeffersonDave Jefferson

                                                                                        1262




                                                                                        1262






























                                                                                            draft saved

                                                                                            draft discarded




















































                                                                                            Thanks for contributing an answer to Stack Overflow!


                                                                                            • Please be sure to answer the question. Provide details and share your research!

                                                                                            But avoid



                                                                                            • Asking for help, clarification, or responding to other answers.

                                                                                            • Making statements based on opinion; back them up with references or personal experience.


                                                                                            To learn more, see our tips on writing great answers.




                                                                                            draft saved


                                                                                            draft discarded














                                                                                            StackExchange.ready(
                                                                                            function () {
                                                                                            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f1667153%2fupdating-class-file-in-jar%23new-answer', 'question_page');
                                                                                            }
                                                                                            );

                                                                                            Post as a guest















                                                                                            Required, but never shown





















































                                                                                            Required, but never shown














                                                                                            Required, but never shown












                                                                                            Required, but never shown







                                                                                            Required, but never shown

































                                                                                            Required, but never shown














                                                                                            Required, but never shown












                                                                                            Required, but never shown







                                                                                            Required, but never shown







                                                                                            Popular posts from this blog

                                                                                            404 Error Contact Form 7 ajax form submitting

                                                                                            How to know if a Active Directory user can login interactively

                                                                                            TypeError: fit_transform() missing 1 required positional argument: 'X'