从openjdk代码仓库下载源码
- 需要安装Mercurial(hg)版本管理工具。
写道sudo apt-get install mercurial
- 安装Mercurial的hclone扩展插件:
写道hg clone http://bitbucket.org/pmezard/hgforest-crew - 将以下内容添加到$HOME/.hgrc文件中,如果没有则自己创建一个:
写道[extensions]
forest=/home/lichengwu/hgforest-crew/forest.py
fetch= - 下载jdk7源码:
写道hg fclone http://hg.openjdk.java.net/jdk7/jdk7
cd jdk7/ && sh get_source.sh
直接下载源码包[推荐]
安装编译必须组件
- 安装gcc、g++、make等
写道sudo apt-get install build-essential
- 安装ant 1.7以上
写道sudo apt-get install ant
- 安装XRender
写道sudo apt-get install libxrender-dev
sudo apt-get install xorg-dev - 安装alsa
写道sudo apt-get install libasound2-dev
- Cups
写道sudo apt-get install libcups2-dev
- 安装jdk6
写道#一般ubuntu都自带,没有的话
sudo apt-get install openjdk-6-jdk -
我是使用的oracle的jdk6,可以编译成功
- 安装零碎的工具包
写道sudo apt-get install gawk zip libxtst-dev libxi-dev libxt-dev
测试编译脚本:
#disable JAVA_HOME
export -n JAVA_HOME
export ALT_JDK_IMPORT_PATH=/usr/belleing/java
make sanity BUILD_JAXWS=false BUILD_JAXP =false
编译脚本:
# cd jdk source code folder
cd ~/workspace/openjdk
# export ALT_BOOTDIR
export LANG=C ALT_BOOTDIR=/usr/belleing/java
# set build profile,first 'chmod +x jdk_generic_profile.sh'
jdk/make/jdk_generic_profile.sh
# disable JAVA_HOME
export -n JAVA_HOME
# export ALT_JDK_IMPORT_PATH
export ALT_JDK_IMPORT_PATH=/usr/belleing/java
# start build
export ALLOW_DOWNLOADS=true
make DEBUG_NAME=all_fastdebug
#make DEBUG_NAME=all_fastdebug BUILD_JAXWS=false BUILD_JAXP=false
下面就是解决make出现的各种问题和解决方案:
1.ERROR: You do not have access to valid Cups header files.
需要安装cpus的dev包
2.ERROR: The version of ant being used is older than the required version of '1.7.1'. The version of ant found was ''.
这说明没有装ant
3. ERROR: FreeType version 2.3.0 or higher is required.
安装freetype的dev包
4. ERROR: You seem to not have installed ALSA 0.9.1 or higher.
不需要从ALSA官网下载alsa-dev和alsa-drive, ubuntu提供包的
5. ERROR: echo "*** This OS is not supported:" 'uname -a'; exit 1;
很奇怪的错误,anyway,注释掉hotspot/make/linux/Makefile里面的checkOS
#ifeq ($(DISABLE_HOTSPOT_OS_VERSION_CHECK)$(EMPTY_IF_NOT_SUPPORTED),)
# $(QUIETLY) >&2 echo "*** This OS is not supported:" `uname -a`; exit 1;
#endif
Update: 最好的办法是在make参数后面添加 DISABLE_HOTSPOT_OS_VERSION_CHECK=OK 即可
6. ERROR: error: "__LEAF" redefined [-Werror]
这个是已知的bug(http://hg.openjdk.java.net/hsx/hotspot-comp/hotspot/rev/a6eef545f1a2), 在hopspot下打入该patch(http://hg.openjdk.java.net/hsx/hotspot-comp/hotspot/raw-rev/a6eef545f1a2)即可
7. ERROR error: converting ‘false’ to pointer type ‘methodOop’ [-Werror=conversion-null]
这个的问题是把 false 转换成 NULL的时候出错了
同样在hotspot下 打入该 patch(http://hg.openjdk.java.net/hsx/hotspot-rt/hotspot/raw-rev/f457154eee8b)
8. ERROR gcc: error: unrecognized command line option '-mimpure-text'
这个-mimpure-text是gcc给Solaris的编译选项,所以注释掉即可
文件在./jdk/make/common/shared/Compiler-gcc.gmk +70
9. ERROR undefined reference to 'snd_pcm_format_**'
folow this link Build openjdk in Ubuntu 11.10
在jdk/make/javax/sound/jsoundalsa/Makefile 里面
编译成功!
、
参考资料:
编译:http://hg.openjdk.java.net/jdk7/build/raw-file/tip/README-builds.html
http://hadwinzhy.gitcafe.com/blog/2013/01/21/compile-jdk/
http://wendal.net/420.html
http://thebye85.iteye.com/blog/1545311
http://rednaxelafx.iteye.com/blog/875957
关于为啥要自己编译jdk:http://rednaxelafx.iteye.com/blog/1549577