Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

JAR Files

Options
  • 18-04-2007 10:55pm
    #1
    Registered Users Posts: 995 ✭✭✭


    Is it possible to update a .class file in a JAR archive?

    using jar uf XXX.jar file.class

    or do you always need to rebuild the complete jar file?

    pretty sure you can't but wanted to make really sure


Comments

  • Registered Users Posts: 33 TabulaRasa


    Just unzip the jar file using Winzip/7Zip or whatever. You will notice that there are directories created for each of the packages. Now just replace the class in the directory you wish. :D


  • Registered Users Posts: 3,886 ✭✭✭cgarvey


    Checkout the help of jar
    jar --help
    
    and specifically the -u flag.
    # edit text.txt
    
    jar -cf my.jar text.txt
    
    # edit text.txt
    
    jar -uf my.jar text.txt
    

    Should do what you're after


  • Registered Users Posts: 995 ✭✭✭cousin_borat


    cgarvey wrote:
    Checkout the help of jar
    jar --help
    
    and specifically the -u flag.
    I had tried that but it won't replace a file that is already in the jar. As far as I can see -u only will update the jar with a new file. I ended up unpacking the jar contents, adding the .class file to the directory and repacking into a jar again.


  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    Jar files are basically zip files. You can just unzip it and replace it. The only issue would be if the jar or class file is signed in which case you would need to update the manifest file.


  • Moderators, Science, Health & Environment Moderators Posts: 10,079 Mod ✭✭✭✭marco_polo


    I had tried that but it won't replace a file that is already in the jar. As far as I can see -u only will update the jar with a new file. I ended up unpacking the jar contents, adding the .class file to the directory and repacking into a jar again.

    jar -uf test.jar test.class is definately right regardless of whether or not the file exists already it should be saved to the jarfile.

    I use this comand all the time in build scripts at work to edit Manifest files etc.


  • Advertisement
  • Registered Users Posts: 3,886 ✭✭✭cgarvey


    I had tried that but it won't replace a file that is already in the jar.

    In my example above, it works. So maybe it only works on text files, but that example works for me (JDK1.5)


  • Registered Users Posts: 995 ✭✭✭cousin_borat


    Hi there,

    the jar files had a manifest file that needed to be updated as well. Once this was done the new class file was added to the jar fine.

    Thanks for your help!


Advertisement