Building OpenJDK on Windows
Below are steps which I had to do to make it happen. I assume machine already has Visual Studio 2010 installed. I have a feeling that Express version should work just fine, but I haven’t tried.
- Install cygwin. Ensure that you have installed all packages listed here, some of them are not installed by default. Just in case, here is the copy of that table, but it is recommended to verify with the master source:
Binary Name Category Package Description ar.exe Devel binutils The GNU assembler, linker and binary utilities make.exe Devel make The GNU version of the ‘make’ utility built for CYGWIN. m4.exe Interpreters m4 GNU implementation of the traditional Unix macro processor cpio.exe Utils cpio A program to manage archives of files gawk.exe Utils awk Pattern-directed scanning and processing language file.exe Utils file Determines file type using ‘magic’ numbers zip.exe Archive zip Package and compress (archive) files unzip.exe Archive unzip Extract compressed files in a ZIP archive free.exe System procps Display amount of free and used memory in the system Do not forget to add cygwin’s ‘bin’ folder into the PATH.
- Install Mercurial from here and add ‘hg’ to the PATH.
- Install Microsoft Windows SDK for Windows 7 and .NET Framework 4.
- Install DirectX SDK. JDK requires v9.0, but I couldn’t find it easily. So I decided not to bother and installed the latest one. Seems like it’s working just fine.
- Bootstrap JDK is required for the build. It just happened that I used JDK6, but suppose, any version >JDK6 will work with no probs.
- Download and install Ant. I used version 1.8.2. Add Ant to the PATH.
- Checkout sources. For a number of reasons it was the most complicated part. ‘hg’ is not particularly stable, so some things which are supposed to be done my scripts, had be done manually.
So, to start run this in command line:
hg clone --verbose --pull http://hg.openjdk.java.net/jdk7u/jdk7u <some_folder>\openjdk7'
This should download root folder with some helper scripts.
Then in cygwin go to just created ‘openjdk7’ folder and run ‘get_source.sh’. ‘get_source.sh’ may fail or just hang (and that’s exactly what happened to me). If it does, then you may try to to use ‘–pull’ flag (pull protocol for metadata). I’m not absolutely sure why, but it helped me. Unfortunately, scripts are not written in very friendly manner and there is no way to pass any ‘hg’ arguments to sources retrieval script. So you need to go to ‘make\scripts\hgforest.sh’ and add ‘–pull’ to every invocation of ‘hg clone’.
And if even after adding ‘–pull’ it still fails, well… just give up and run these commands manually:
hg clone --verbose --pull http://hg.openjdk.java.net/jdk7u/jdk7u/corba corba hg clone --verbose --pull http://hg.openjdk.java.net/jdk7u/jdk7u/hotspot hotspot hg clone --verbose --pull http://hg.openjdk.java.net/jdk7u/jdk7u/jaxp jaxp hg clone --verbose --pull http://hg.openjdk.java.net/jdk7u/jdk7u/jaxws jaxws hg clone --verbose --pull http://hg.openjdk.java.net/jdk7u/jdk7u/jdk jdk hg clone --verbose --pull http://hg.openjdk.java.net/jdk7u/jdk7u/langtools langtools
Hopefully now you have sources and can contunue :)
- Build requires some external binaries and a version of ‘make.exe’, which works under windows. ‘make’ which comes with cygwin doesn’t really work, because has some problems with drive letters in path names.
Next is we need to compile a couple of files. One is fixed version of ‘make.exe’. The other is FreeType library, which is only available to download as source.
If you are not interested in compiling all that stuff and want just compile JDK with less hassle, I would recommend to download binaries from here (that’s my Drive). Unpack ‘make.exe’ into ‘openjdk7/bin’. Note, that ‘make.exe’ from the package is quite old and requires cygintl-3.dll, which is not provided with current cygwin. To fix it, just copy cygintl-8.dll -> cygintl-3.dll.
Freetype lib and dll has to be put in folder referenced by ‘ALT_FREETYPE_LIB_PATH’ conf variable (see Step 13). Also, some Freetype headers are still required and are located by make via ‘ALT_FREETYPE_HEADERS_PATH’ variable (see Step 13). It means you will also need to download the source code.If you are not looking for a simple solution and want to compile these binaries yourself, then follow these instructions:
- Download make 3.82 from here and unpack it. Find ‘config.h.W32’ and uncomment line with ‘HAVE_CYGWIN_SHELL’ definition. Open make_msvc_net2003.sln solution in Visual Studio, select ‘Release’ configuration and make a build. In ‘Release’ folder, you will get ‘make_msvc.net2003.exe’, rename it to ‘make.exe’.
- Now compile FreeType:
- Download source of FreeType v.2.4.7 from here.
- Unpack it somewhere and open ‘\builds\win32\vc2010\freetype.sln’ in Visual Studio.
- Goto project properties (right click on project in project tree) and in ‘Configuration Properties/General/Configuration type’ select ‘Dynamic Library (.ddl)’ and rename output to ‘freetype’.
- Update ftoption.h, add following two lines:
#define FT_EXPORT(x) __declspec(dllexport) x
#define FT_BASE(x) __declspec(dllexport) x - Make a build and you will get dll & lib in ‘objs\win32\vc2010’.
- Do not forget to assign appropriate values to ‘ALT_FREETYPE_LIB_PATH’ and ‘ALT_FREETYPE_HEADERS_PATH’ variables (see Step 13).
- I had some problems with javadoc generation, which was failing with OutOfMemory. In order to fix it, I had to change ‘openjdk7\jdk\make\docs\Makefile’.
This code:ifeq ($(ARCH_DATA_MODEL),64) MAX_VM_MEMORY = 1024 else ifeq ($(ARCH),universal) MAX_VM_MEMORY = 1024 else MAX_VM_MEMORY = 512 endif
has to be replaed with this:
ifeq ($(ARCH_DATA_MODEL),64) MAX_VM_MEMORY = 1024 else ifeq ($(ARCH),universal) MAX_VM_MEMORY = 1024 else MAX_VM_MEMORY = 1024 endif
- Copy ‘msvcr100.dll’ to drops:
cp /cygdrive/c/Program\ Files\ \(x86\)/Microsoft\ Visual\ Studio\ 10.0/Common7/Packages/Debugger/X64/msvcr100.dll ./drops/
- Ensure that cygwin’s ‘find.exe’ in the PATH before the Windows’ one. The easiest way to do so is to copy it into ‘openjdk7/bin’, which is then set at the beginning of current PATH.
- Create a batch file similar to the following one. Do not forgot to update paths appopriately:
ALT_BOOTDIR=C:/Stuff/java_libs/jdk1.6.0_25 ANT_HOME=C:/Stuff/java_libs/apache-ant-1.8.2 JAVA_HOME= CLASSPATH= PATH=C:/Stuff/openjdk7/bin;%PATH% ALLOW_DOWNLOADS=true ALT_MSVCRNN_DLL_PATH=C:/Stuff/java_libs/openjdk7/drops C:\WINDOWS\system32\cmd.exe /E:ON /V:ON /K 'C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd' /Release /xp /x86
- Run batch file. Now you have fully configured environment, which is ready for build. Run ‘bash’ and from the shell execute ‘make’:
make ARCH_DATA_MODEL=32 ALT_OUTPUTDIR=C:/Users/Stas/Stuff/java_libs/openjdk7/output_32 ALT_FREETYPE_LIB_PATH=C:/Users/Stas/Stuff/java_libs/openjdk7/freetype-2.4.7/objs/win32/vc2010 ALT_FREETYPE_HEADERS_PATH=C:/Users/Stas/Stuff/java_libs/openjdk7/freetype-2.4.7/include ALT_BOOTDIR=C:/Users/Stas/Stuff/java_libs/jdk1.6.0_25 ALT_DROPS_DIR=c:/OpenJDK/ALT_DROPS_DIR ALT_DROPS_DIR=C:/Users/Stas/Stuff/java_libs/openjdk7/drops HOTSPOT_BUILD_JOBS=4 PARALLEL_COMPILE_JOBS=4 2>&1 | tee C:/Stuff/java_libs/openjdk7/output_32.log
This will start build of 32bit JDK.
- Have a coffee, tea, or whatever you prefer to have and then after about an hour or so you should see something like this:
#-- Build times ---------- Target all_product_build Start 2012-09-01 23:08:55 End 2012-09-01 23:55:48 00:02:35 corba 00:06:46 hotspot 00:00:30 jaxp 00:00:51 jaxws 00:35:30 jdk 00:00:37 langtools 00:46:53 TOTAL -------------------------
Reference: Building OpenJDK on Windows from our JCG partner Stanislav Kobylansky at the Stas’s blog blog.
Hi My system is win 7 32 bit, My cygwin is the latest one(1.7.30). I followed all steps as you wrote. But I got Error: ## Starting jdk Generating exceptions classes Compiling 9167 files for BUILD_JDK Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. Compiling 235 files for BUILD_SECURITY Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Could not start process! Failed with error 2: The system cannot find… Read more »