javabatch-fileglassfishunzipicacls

Can't extract a zip file with jar -xf even after granting full permissions using icacls


First i had to suffer to make the icalcs grant full permissions to everyone in a folder as i didn't know that i should write "Tout le monde" instead of "everyone" as my windows 7 language is french and actually i needed this command for that i can unzip a zip file in the same permissions altered folder.

the code of my batch file is the following :

call xcopy glassfish-4.1.zip C:\Users\Feki\Desktop\vvv2
icacls C:\Users\Feki\Desktop\vvv2 /grant "Tout le monde":f
call C:\Program Files\Java\jdk1.7.0_40\bin>jar xf C:\Users\Feki\Desktop\vvv2\glassfish-4.1.zip
ECHO.
ECHO Press any key to exit. 
pause>null

the log indicated that the icalcs was successful but when the extraction starts i got an ' access denied' message

---- EDIT ----

i've tried to make sure that i have all permission granted on the zip file to extract so i added

icacls C:\Users\Feki\Desktop\vvv2\* /grant "Tout le monde":f

after the first icacls but the extraction still didn't work


Solution

  • First I want to say that I think your script looks a little bit weired.

    In the first line

    call xcopy glassfish-4.1.zip C:\Users\Feki\Desktop\vvv2
    

    you are copying the zip file to a folder on the Desktop, this already requires write access rights in C:\Users\Feki\Desktop\vvv2 or it won't work.

    In the next line you try to set the access rights for this folder:

    icacls C:\Users\Feki\Desktop\vvv2 /grant "Tout le monde":f
    

    As described, this doesn't make much sense because you already have written the zip file to this folder, therefore you must have at least write access rights.

    Now to the problem, the call:

    call C:\Program Files\Java\jdk1.7.0_40\bin>jar xf C:\Users\Feki\Desktop\vvv2\glassfish-4.1.zip
    

    is something which shouldn't work anyway because there is a space between Program and Files. I don't know what this bin>jar should be but if this works for you, then you may use it in this way.

    I would write it like this:

    call "%ProgramFiles%\Java\jdk1.7.0_40\bin\jar.exe" xf C:\Users\Feki\Desktop\vvv2\glassfish-4.1.zip
    

    If this call gives you an Access denied. message then you probably don't have write access rights in the current path of the command line.

    Note that the jar utility will extract the content of the zip file to the current path of the command line. That means if you are in c:\ then it will extract the content to c:\ and if you are in c:\bla\ then it will extract the content to c:\bla\. (It doesn't make a difference if you call it with the full path or only jar when it is in your PATH var.)

    So this looks like you don't have the right access rights in the path where your glassfish-4.1.zip is, because this is the current path of your command line. I guess you want to extract the content to the folder on the Desktop. To do this, just change the current path to this folder before issuing the extract call.

    I guess the script could look like this:

    call xcopy glassfish-4.1.zip C:\Users\Feki\Desktop\vvv2
    cd C:\Users\Feki\Desktop\vvv2\
    call "%ProgramFiles%\Java\jdk1.7.0_40\bin\jar.exe" xf glassfish-4.1.zip
    

    See also: