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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

JAR Files

  • 18-04-2007 9:55pm
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 Posts: 3,889 ✭✭✭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, Registered Users 2 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, Registered Users 2 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,088 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, Registered Users 2 Posts: 3,889 ✭✭✭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, Registered Users 2 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