---
title: "在Ubuntu12.04LTS上编译JDK7"
author: "kingquake21"
date: "2012-12-25T17:15:18Z"
tags: []
categories: ["编程语言"]
slug: "ubuntu12-04lts-jdk7"
draft: false
lastmod: "2012-12-25T17:56:37Z"
id: 1753959
url: "https://kingquake21.iteye.com/blog/1753959"
---

1、下载mercurial，源码根目录有个文件README-builds.html，非常详细，可以参考

hg fclone http://hg.openjdk.java.net/jdk7/jdk7

 

2、要先安装OpenJDK6，记录一下安装的地方，在下面的环境变量里面会用到

我的是/usr/lib/jvm/java-1.6.0-openjdk-amd64/

 

3、安装JDK7所需要的依赖包

sudo apt-get build-dep openjdk-7

 

4、源码中有一个bug，需要修改一下，在编译时发现会与glibc中的一个定义冲突

src/share/vm/runtime/interfaceSupport.hpp:430:0: error: "\_\_LEAF" redefined \[-Werror]

/usr/include/x86\_64-linux-gnu/sys/cdefs.h:44:0: note: this is the location of the previous definition

[http://hg.openjdk.java.net/hsx/hotspot-comp/hotspot/rev/a6eef545f1a2](http://hg.openjdk.java.net/hsx/hotspot-comp/hotspot/rev/a6eef545f1a2)

 

5、在编译时会遇到和"javax/sound/jsoundalsa"相关的一个错误，网上搜了一下这个貌似是openjdk的一个bug，有人提供了补丁http://mail.openjdk.java.net/pipermail/build-dev/2012-January/005382.html。只需要修改openjdk/jdk/make/javax/sound/jsoundalsa目录下的Makefile文件，找到LDFLAGS += -lasound 

修改为：OTHER\_LDLIBS += -lasound

 

6、设置如下环境变量

 

```
#!/bin/bash  
  
export LANG=C  
export ALT_BOOTDIR=/usr/lib/jvm/java-1.6.0-openjdk-amd64/
export ALLOW_DOWNLOADS=true                                                                                                                    
export USE_PRECOMPILED_HEADER=true  
export SKIP_DEBUG_BUILD=false  
export SKIP_FASTDEBUG_BUILD=true  
export DISABLE_HOTSPOT_OS_VERSION_CHECK=true  
export DEBUG_NAME=debug  
unset CLASSPATH  
unset JAVA_HOME           
  
make sanity  && make
```

 

然后执行了挺长一段时间，就生成了jdk7/build/linux-amd64，察看版本

 

openjdk version "1.7.0-internal-debug"

OpenJDK Runtime Environment (build 1.7.0-internal-debug-wz\_2012\_12\_25\_15\_46-b00)

OpenJDK 64-Bit Server VM (build 21.0-b17-jvmg, mixed mode)

 

 

参考：

[http://lc87624.iteye.com/blog/1542354](http://lc87624.iteye.com/blog/1542354)

[http://blog.csdn.net/kindazrael/article/details/7266314](http://blog.csdn.net/kindazrael/article/details/7266314)

 

 

如果只想单独编译hotspot，可以这样：

bash:~/mercurial/$hg clone http://hg.openjdk.java.net/jdk7/hotspot/hotspot

bash:~/mercurial/$cd hotspot/make

bash:~/mercurial/hotspot/make$LANG=C ALT\_BOOTDIR=/usr/lib/jvm/java-6-openjdk/ HOTSPOT\_BUILD\_JOBS=5 ARCH\_DATA\_MODEL=64 ALT\_OUTPUTDIR=../../build/hotspot\_debug make jvmg jvmg1 2&gt;&1 | tee ../../build/hotspot\_debug