Google+ ZACARÉS: April 2014

Translate

2014/04/26

Windows batch to download and make a portable JDK

I am a fan of portable apps and don't like to install stuff unless there is no other choices, as installation on Windows platform usually will introduce some unexpected "side-effect".

JDK is one of the tool that I need but don't want to install during development. I want to perform some automated tasks to set up a portable development environment (for android development). But downloading and extracting the JDK in a workable state are a bit tricky. Here is what I have performed to automate the process under Windows environment.

To automate the task using Windows batch script, you will need to acquire the following command tools first.

  • wget.exe
  • 7z.exe and 7z.dll
To download the JDK (e.g. jdk-7u55-windows-i586.exe) from Oracle using wget.exe and extract the JDK to.\jdk_1.7.0_55, copy the following contents to a text file and save it as "getJDK.bat" in the folder where wget.exe and 7z.exe resided.

@echo off
"%~dp0wget.exe" --no-check-certificate -O "%~dp0jdk-7u55-windows-i586.exe" "http://download.oracle.com/otn-pub/java/jdk/7u55-b13/jdk-7u55-windows-i586.exe" --no-cookies --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie"
"%~dp07z.exe" x -y "%~dp0jdk-7u55-windows-i586.exe" -o"%~dp0jdk_1.7.0_55"
"%~dp07z.exe" x -y "%~dp0jdk_1.7.0_55\tools.zip"  -o"%~dp0jdk_1.7.0_55"
del "%~dp0jdk_1.7.0_55\tools.zip"
for /r "%~dp0jdk_1.7.0_55" %%x in (*.pack) do "%~dp0jdk_1.7.0_55\bin\unpack200" "%%x" "%%x.jar"
for /r "%~dp0jdk_1.7.0_55" %%y in (*.pack) do ren "%%y" "%%~ny.pack.org"
for /r "%~dp0jdk_1.7.0_55" %%z in (*.pack.jar) do ren "%%z" "%%~nz"
for /r "%~dp0jdk_1.7.0_55" %%a in (*.pack) do ren "%%a" "%%~na.jar"
for /r "%~dp0jdk_1.7.0_55" %%y in (*.pack.org) do del "%%y"

And lastly, double click "getJDK.bat" to start the process. After the process finished, the folder "jdk_1.7.0_55" should contain a workable JDK.

Don't forget to set the JAVA_HOME environment variable to point to your JDK folder and also add the %JAVA_HOME%\bin to the PATH environment in order to use the JDK wherever you are.

2014/04/12

OpenSSL Heartbleed bug updates - compile openssl 1.0.1g using TDM-GCC

Due to the OpenSSL Heartbleed issue, you should update openssl to the latest 1.0.1g. But searching the web, there is no suitable precompile version for Windows that suit my need. So I have to get my hand dirty to compile by myself.

To compile, you need the following tools on hand.
I've install the above stuff into the following folders respectively.
  • ActivePerl: c:\dev\perl
  • TDM-GCC: c:\dev\tdm\x32
  • TDM64-GCC: c:\dev\tdm\x64
  • MSYS: c:\dev\msys
Of course, you will need to have openssl-1.0.1g.tar.gz and I've placed it under c:\dev\openssl.


All the steps below should be carried out inside the MSYS prompt, so you need to start MSYS first by double-click the msys.bat inside MSYS installation folder.

export PATHBACKUP=$PATH
export PATH="/c/dev/tdm/x32/bin:/c/dev/perl/bin:$PATHBACKUP"
cd "/c/dev/openssl"
tar -zxvf openssl-1.0.1g.tar.gz
mv openssl-1.0.1g x32
cd x32
./Configure --prefix=$PWD/dist no-idea no-mdc2 no-rc5 shared mingw
make depend && make && make install

export PATH="/c/dev/tdm/x64/bin:/c/dev/perl/bin:$PATHBACKUP"
cd "/c/dev/openssl"
tar -zxvf openssl-1.0.1g.tar.gz
mv openssl-1.0.1g x64
cd x32
./Configure --prefix=$PWD/dist no-idea no-mdc2 no-rc5 shared mingw64
make depend && make && make install

NOTE: You should not extract the openssl-1.0.1g.tar.gz with any archiver, e.g. 7zip under Windows. You should extract using the tar command inside MSYS prompt instead.

The reason why I need to have both TDM64-GCC and TDM-GCC is that I cannot find a way to tell MSYS to use x32 libraries and toolchains with TDM64-GCC. The work around is to set the PATH for different toolchains folder with different architectures.

If you don't want to compiled by yourself, you may download my precompiled openssl-1.0.1g-tdm-tdm64.7z which use tdm-gcc to build with both x32 and x64 libraries included.

Name :openssl-1.0.1g-tdm-tdm64.7z
Size :3715883 bytes
MD5  :A9D23198AA4F6A41DA7954AB7CE8ABFE
SHA1 :9E225DAA6A793618009CFD729420AD5CDEB0A38D