In today’s post we see how to install the Java Development Kit (JDK) on a Windows machine without having administration permissions. Without these rights, in fact, you can’t install the jdk through the step-by-step wizard but it’s necessary to install it manually.
First, after downloading the correct version of the jdk for our operating system, we try to run the installation by double clicking the icon. In my case the operating system is Windows 7 64bit, so the version of the jdk is jdk-7u67-windows-x64. Trying to launch the installation we get the following error, which indicates that we don’t have sufficient privileges to install it and we must log in as administrator.
But we can’t log in as administrators, so we have to find an alternative solution.
We open the jdk installation file, jdk-7u67-windows-x64.exe , with 7zip and look at its contents. As we can see in the figure below, the content is a zip file called tools.zip.
Entering further within this zip file to see its contents we get what shown in the figure:
At this point we extract all the contents into a folder on the file system in our user area, for example: C:\Users\MolinariD\jdk-7u67.
Browsing through the contents extracted from the zip and copied to the folder, we will find some files with extension .pack, precisely under the folders lib and jre/lib.
The following figure shows the contents of the folder /jre/lib where we can see some of these .pack files.
These files are nothing more than good old .jar files further compressed with a tool called pack200 supplied directly with the jdk. What we have to do is to unpack these .pack files to their relevant .jar files using the “inverse” command, unpack200. For further details, see the official documentation of pack200 and unpack200 commands.
Now we go into the /lib directory of the JDK and execute a dir command to get the list of available .pack files. We see that there is a file called “tools.pack”, so we execute the following command: unpack200 tools.pack tools.jar.
The same operation performed on the file tools.pack needs to be executed for all the .pack files present in the jre/lib folder. To do this, however, we don’t want to repeat manually the unpack command for each of them, but instead we write a DOS script that will do it for us (as in my case JDK needs to be installed in this way on several machines).
What our script will do is:
1) require to the user the path of the folder containing the jdk
2) search for all .pack files present in subdirectories
3) run the unpack200 command on all these files
For point 1) we use the SET command with the /P option that allows us to get a value inserted as input by the user, showing him a prompt message.
For point 2) we use the FORFILES command that allows us to select a group of files and execute a specific command on them. FORFILES offers the following options we’re going to use:
/P specifies the path from which to start the search
/S indicates to search recursively also on subdirectories
/M allows you to define a search filter in order to filter the files according to a particular pattern
/C is the command to execute on the files, which must be enclosed in double quotes ”
For point 3) we simply invoke the command unpack200 providing as parameters the name of the .pack file and its equivalent with the replacement of the extension in .jar that we can get with a replace instruction (outputName=%outputName:pack=jar%)
Here’s our script:
echo off REM Author: Molinari Davis - www.davismol.net REM Version: 0.1 REM Date: 29/08/2014 if "%1"=="/processFile" goto processFile SET /P commandPath=Insert the jdk folder path: SET commandName=\jre\bin\unpack200.exe FORFILES /p %commandPath% /s /m *.pack /c "cmd /c call "%~f0" /processFile @path" goto :EOF :processFile SET outputName=%2 SET outputName=%outputName:pack=jar% SET fullCommand=%commandPath%%commandName% %2 %outputName% REM echo %fullCommand% %fullCommand% if %ERRORLEVEL% GEQ 1 ( echo ERROR in extraction of file: %outputName% ) else ( echo Extracted file: %outputName% )
Now that we have created the script we just have to run it. Once launched, as expected, we are asked to indicate the path where the folder is located in the jdk:
In this case I had unzipped the folder to the path C:\Users\MolinariD\jdk-7u67 so now I enter this path as input of the script:
At this point, the script searchs for of all the .pack files present in subfolders and extracts for each of them the corresponding .jar file.
The result of the execution of the script is shown in the following figure:
As a last step we verify the presence of the .jar file that we expect. Looking for example in the jre/lib folder we see that, for each .pack file there is its corresponding .jar file.
So our script worked and we have a jdk installed and ready to use.
The script created is available for download here: