Sunny Chan blogs Can you see the Logic in my Madness?

Blog server moved to Rocky Linux 9

by Sunny Chan


Posted on Wednesday March 01, 2023 at 03:38am in Linux


The blog server has been migrated to Rocky Linux 9 - as Centos 7 is end of life soon. Containers makes migration pretty easy - it's just as simple as moving the config files over!


Blog software updated with containers

by Sunny Chan


Posted on Sunday March 07, 2021 at 12:44pm in Linux


Another upgrade recently - I used to run the blog with a tomcat instance directly installed in the OS but I have just containerized it with podman. I used Tomcat docker image and basically mapped the existing data files from my home directory into the container and it pretty much works.

The more challenging part is to convince systemctl to start the blog container every time the system restarts. I use podman as my container runtime as it allows running the container in the user namespace instead of root, which makes it more secure. However it seems that running as user namespace makes it difficult to setup systemctl due to issues with podman. You should follow the advise in this podman bug if you are having trouble:

  • Set Requires/After to user@<uid>.service to ensure all the user environment is setup before systemctl starts the blog container
  • You will need to run "loginctl enable-linger" for the user (see the issue comment)

Once it is all set it works like a treat. Now I can move my blog to any vps hosts that support docker container without dependent on the whole OS setup


Roller with https

by Sunny Chan


Posted on Wednesday July 25, 2018 at 12:40am in Linux


I have just migrated my roller to use https, and just for those who will need to do it later, you will need to make roller to replace all the URL with https. To do this, add the following to roller-custom.properties:


weblog.absoluteurl.[blog name]=https://someurl/roller


where blog name is the name of your blog, displayed at the top when you get into the configuration page. 


Updated OpenJDK-build docker image

by Sunny Chan


Posted on Tuesday September 12, 2017 at 06:31am in Linux


Since I have started my new job I have quite a bit of opportunity to do a bit of Docker deployment. So I have spend some time to update my docker image for openjdk build.


What's new:




  1. The image is now based on latest CentOS 7 (Oracle builds with Oracle Linux which is basically rebranded RHEL/Centos)

  2. It now has a docker build file, git hub repo and automatic build on Docker hub

  3. The default start up will now be user openjdk, and you could mount your data directory as home.

  4. I have put nano, git and hg in the image for your convience


This image will be able to build latest JDK8 and JDK9 source code.  



Here is an example on how to build an image 


#notice that you need :Z at the end of mount so that it fixes up selinux
#If you use default userid you can just mount your home dir (xxx = your id on host).
sudo docker run --rm -it -v /home/xxx:/home/openjdk:Z sunnythepooh/openjdk-build-docker:latest bash

[openjdk@8a4bc8214db2 ~]$ hg clone http://hg.openjdk.java.net/jdk9/jdk9
destination directory: jdk9
requesting all changes
adding changesets
adding manifests
adding file changes
added 2628 changesets with 4461 changes to 468 files
updating to branch default
322 files updated, 0 files merged, 0 files removed, 0 files unresolved
[openjdk@8a4bc8214db2 jdk9]$ bash get_source.sh
WARNING: Mercurial version 2.6.3 or later is recommended. /usr/bin/hg is version 2.6.2
# Repositories: corba jaxp jaxws langtools jdk hotspot nashorn
corba: hg clone http://hg.openjdk.java.net/jdk9/jdk9/corba corba
jaxp: hg clone http://hg.openjdk.java.net/jdk9/jdk9/jaxp jaxp
corba: requesting all changes
jaxp: requesting all changes
jaxp: adding changesets
corba: adding changesets
corba: adding manifests
jaxp: adding manifests
corba: adding file changes
jaxp: adding file changes
corba: added 876 changesets with 5451 changes to 2597 files
corba: updating to branch default
corba: 1201 files updated, 0 files merged, 0 files removed, 0 files unresolved
jaxws: hg clone http://hg.openjdk.java.net/jdk9/jdk9/jaxws jaxws
jaxws: requesting all changes
jaxws: adding changesets
jaxws: adding manifests
jaxws: adding file changes
jaxws: added 801 changesets with 21839 changes to 10824 files
jaxws: updating to branch default
jaxws: 3760 files updated, 0 files merged, 0 files removed, 0 files unresolved
langtools: hg clone http://hg.openjdk.java.net/jdk9/jdk9/langtools langtools
langtools: requesting all changes
langtools: adding changesets
langtools: adding manifests
jaxp: added 1153 changesets with 14751 changes to 8449 files
jaxp: updating to branch default
jaxp: 3352 files updated, 0 files merged, 0 files removed, 0 files unresolved
jdk: hg clone http://hg.openjdk.java.net/jdk9/jdk9/jdk jdk
jdk: requesting all changes
jdk: adding changesets
langtools: adding file changes
jdk: adding manifests
langtools: added 4174 changesets with 38097 changes to 11847 files
langtools: updating to branch default
langtools: 9464 files updated, 0 files merged, 0 files removed, 0 files unresolved
hotspot: hg clone http://hg.openjdk.java.net/jdk9/jdk9/hotspot hotspot
hotspot: requesting all changes
hotspot: adding changesets
hotspot: adding manifests
hotspot: adding file changes
jdk: adding file changes
hotspot: added 12824 changesets with 78616 changes to 15832 files
hotspot: updating to branch default
hotspot: 9078 files updated, 0 files merged, 0 files removed, 0 files unresolved
nashorn: hg clone http://hg.openjdk.java.net/jdk9/jdk9/nashorn nashorn
nashorn: requesting all changes
nashorn: adding changesets
nashorn: adding manifests
nashorn: adding file changes
nashorn: added 1928 changesets with 14563 changes to 4181 files
nashorn: updating to branch default
nashorn: 3293 files updated, 0 files merged, 0 files removed, 0 files unresolved
jdk: added 17287 changesets with 152446 changes to 50650 files
jdk: updating to branch default
jdk: 27295 files updated, 0 files merged, 0 files removed, 0 files unresolved
# Repositories: . corba jaxp jaxws langtools jdk hotspot nashorn
.: cd . && hg pull -u
corba: cd corba && hg pull -u
jaxp: cd jaxp && hg pull -u
jaxws: cd jaxws && hg pull -u
langtools: cd langtools && hg pull -u
jdk: cd jdk && hg pull -u
hotspot: cd hotspot && hg pull -u
nashorn: cd nashorn && hg pull -u
corba: pulling from http://hg.openjdk.java.net/jdk9/jdk9/corba
.: pulling from http://hg.openjdk.java.net/jdk9/jdk9
jdk: pulling from http://hg.openjdk.java.net/jdk9/jdk9/jdk
hotspot: pulling from http://hg.openjdk.java.net/jdk9/jdk9/hotspot
nashorn: pulling from http://hg.openjdk.java.net/jdk9/jdk9/nashorn
jaxws: pulling from http://hg.openjdk.java.net/jdk9/jdk9/jaxws
langtools: pulling from http://hg.openjdk.java.net/jdk9/jdk9/langtools
jaxp: pulling from http://hg.openjdk.java.net/jdk9/jdk9/jaxp
jaxws: searching for changes
jaxws: no changes found
hotspot: searching for changes
hotspot: no changes found
nashorn: searching for changes
nashorn: no changes found
corba: searching for changes
corba: no changes found
.: searching for changes
.: no changes found
langtools: searching for changes
langtools: no changes found
jaxp: searching for changes
jaxp: no changes found
jdk: searching for changes
jdk: no changes found
[openjdk@be86432ef9b0 jdk9]$ bash ./configure
Running generated-configure.sh
configure: Configuration created at Mon Sep 11 16:04:08 UTC 2017.
configure: configure script generated at timestamp 1496926402.
checking for basename... /usr/bin/basename
checking for bash... /usr/bin/bash
checking for cat... /usr/bin/cat
checking for chmod... /usr/bin/chmod
checking for cmp... /usr/bin/cmp
checking for comm... /usr/bin/comm
checking for cp... /usr/bin/cp
checking for cut... /usr/bin/cut
checking for date... /usr/bin/date
checking for gdiff... no
checking for diff... /usr/bin/diff
checking for dirname... /usr/bin/dirname
checking for echo... /usr/bin/echo
checking for expr... /usr/bin/expr
checking for file... /usr/bin/file
checking for find... /usr/bin/find
checking for head... /usr/bin/head
checking for gunzip... /usr/bin/gunzip
checking for pigz... no
checking for gzip... /usr/bin/gzip
checking for ln... /usr/bin/ln
checking for ls... /usr/bin/ls
checking for mkdir... /usr/bin/mkdir
checking for mktemp... /usr/bin/mktemp
checking for mv... /usr/bin/mv
checking for nawk... no
checking for gawk... /usr/bin/gawk
checking for printf... /usr/bin/printf
checking for rm... /usr/bin/rm
checking for rmdir... /usr/bin/rmdir
checking for sh... /usr/bin/sh
<!--------------------- MANY LINES LATER --------------------->
====================================================
A new configuration has been successfully created in
/home/openjdk/jdk9/build/linux-x86_64-normal-server-release
using default settings.

Configuration summary:
* Debug level: release
* HS debug level: product
* JDK variant: normal
* JVM variants: server
* OpenJDK target: OS: linux, CPU architecture: x86, address length: 64
* Version string: 9-internal+0-adhoc..jdk9 (9-internal)

Tools summary:
* Boot JDK: openjdk version "1.8.0_141" OpenJDK Runtime Environment (build 1.8.0_141-b16) OpenJDK 64-Bit Server VM (build 25.141-b16, mixed mode) (at /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.141-1.b16.el7_3.x86_64)
* Toolchain: gcc (GNU Compiler Collection)
* C Compiler: Version 4.8.5 (at /usr/bin/gcc)
* C++ Compiler: Version 4.8.5 (at /usr/bin/g++)

Build performance summary:
* Cores to use: 8
* Memory limit: 11783 MB
[openjdk@be86432ef9b0 jdk9]$ make images
Building target 'images' in configuration 'linux-x86_64-normal-server-release'
Compiling 8 files for BUILD_TOOLS_LANGTOOLS
Creating hotspot/variant-server/tools/adlc/adlc from 13 file(s)
Creating support/modules_libs/java.base/libjsig.so from 1 file(s)
Compiling 2 files for BUILD_JVMTI_TOOLS
<!------------------------------------- MANY LINES LATER ----------------------------------------->
----- Build times -------
Start 2017-09-10 16:55:14
End 2017-09-10 17:04:50

00:09:36 TOTAL
-------------------------
Finished building target 'images' in configuration 'linux-x86_64-normal-server-release'

#You should be able to find the build under build/

[openjdk@192f7c9052ff jdk9]$ build/linux-x86_64-normal-server-release/images/jdk/bin/java -version
openjdk version "9-internal"
OpenJDK Runtime Environment (build 9-internal+0-adhoc..jdk9)
OpenJDK 64-Bit Server VM (build 9-internal+0-adhoc..jdk9, mixed mode)




 


My Java story and my latest spat with a famous blogger in HK

by Sunny Chan


Posted on Friday June 02, 2017 at 08:08am in Java


I end up being Mr. Java pretty much by luck - I was in my third year and I was looking for an internship, which is a requirement for my degree. I was pretty late and got rejected in quite a few places until certain manager from IBM come and interview me for a role. The certain lab in IBM actually made quite a few products and I end up working in the Java Technology Center, and my intern project was to port the JVM to Linux/IA-64 (well no one knows it end up being the biggest white elephant of Intel history). And the rest is history.


My whole career was built on Java, and it has brought me the opportunity to work on pretty impressive projects and interesting work. Java feels like my kid and it is like a proud parent seeing that child growing up and used everywhere as it does.


I understand Java is not as "cool" as it used to be, but I believed in the technology and I know what it can and it cannot do. 


Recently, a leaked memo from Hong Kong has suggested that certain components with the new Air Traffic Control system requires reboot every time the heap is at 2.5G. A number of "high profile"(?) IT(?) blogger posted a couple of piece spreading FUD against Java. Java has its problems and if you "hate" it for the right reason backed by evidence, I would more than happy to accept the opinion. However, the blogger decided for no valid reason in his post he accused Java not being suitable for anything serious. I am not going to let that pass.


Now that blogger has accused those who criticized him spreading FUD against Java being a lefty, and they are helping the government to turn an blind eye in the bad governance/project management of the new ATC roll out. Let me be cleared - you are a respected blogger and with a lot of readers who might not know Java. By reading the FUD in the article you are affecting my career and my life work and I will come out fighting against anyone who spread FUD against Java.


Anyway, I have published my rebuttal to his article in other channel so I am not going to re-post it. If he is believe he is right feel to come and have a conversation with me in June Codeaholics meeting about Java, instead of blocking me on the Facebook. 


Centos Docker images for building OpenJDK

by Sunny Chan


Posted on Saturday November 01, 2014 at 09:43pm in Java


I am going to lead an OpenJDK hackathon in Taiwan later this month and I am trying to create an VM image so that people can get up and running quickly. Then last couple of weeks I came across Docker, which is a very simple container which allows easy deployment of images to your machine. So I have decided to try and see whether I can create some docker images for Hackathon use. Here is what I have come up with:


https://registry.hub.docker.com/u/sunnythepooh/openjdk-build


There are two images, one build with Centos 6 base image and one with Centos 7. Out of the container there are all the dependency you need to build OpenJDK 9, and an openjdk user. Once you pull the image down, you can login as openjdk and use mercurial to download openjdk and build straight away.


For Linux, you can install docker directly on any modern distribution. On Windows/MacOS you can use Boot2docker which would give you a very small Linux VM which you can run docker command from and you can take a look at the following command sequence to compile a OpenJDK 9 build:


[schan@sandybridge ~]$ sudo docker run -t -i sunnythepooh/openjdk-build:centos6 /bin/bash
bash-4.2# login openjdk
Password:
Last login: Fri Oct 31 05:02:55 on pts/1
-bash: cannot set terminal process group (-1): Inappropriate ioctl for device
-bash: no job control in this shell
[openjdk@e583ed8a4e04 ~]$ hg clone http://hg.openjdk.java.net/jdk9/dev jdk9
requesting all changes
adding changesets
adding manifests
adding file changes
added 1213 changesets with 1750 changes to 151 files
updating to branch default
93 files updated, 0 files merged, 0 files removed, 0 files unresolved
[openjdk@e583ed8a4e04 ~]$ cd jdk9
[openjdk@e583ed8a4e04 jdk9]$ ls
ASSEMBLY_EXCEPTION Makefile README-builds.html common get_source.sh modules.xml
LICENSE README THIRD_PARTY_README configure make test
[openjdk@e583ed8a4e04 jdk9]$ bash get_source.sh
WARNING: Mercurial version 2.6.3 or later is recommended. /bin/hg is version 2.6.2
# Repositories: corba jaxp jaxws langtools jdk hotspot nashorn
corba: hg clone http://hg.openjdk.java.net/jdk9/dev/corba corba
jaxp: hg clone http://hg.openjdk.java.net/jdk9/dev/jaxp jaxp
corba: requesting all changes
.............................................................................cut for brevity..........................................................................
nashorn: searching for changes
nashorn: no changes found
jdk: searching for changes
jdk: no changes found
jaxws: searching for changes
jaxws: no changes found
jaxp: searching for changes
jaxp: no changes found
.: searching for changes
hotspot: searching for changes
.: no changes found
hotspot: no changes found
corba: searching for changes
corba: no changes found
langtools: searching for changes
langtools: no changes found
[openjdk@e583ed8a4e04 jdk9]$ bash ./configure
Running generated-configure.sh
configure: Configuration created at Sat Nov 1 05:15:04 GMT 2014.
configure: configure script generated at timestamp 1414663067.
checking for basename... /bin/basename
checking for bash... /bin/bash
checking for cat... /bin/cat
checking for chmod... /bin/chmod
checking for cmp... /bin/cmp
checking for comm... /bin/comm
checking for cp... /bin/cp
checking for cut... /bin/cut
checking for date... /bin/date
.............................................................................cut for brevity..........................................................................
====================================================
A new configuration has been successfully created in
/home/openjdk/jdk9/build/linux-x86_64-normal-server-release
using default settings.

Configuration summary:
* Debug level: release
* HS debug level: product
* JDK variant: normal
* JVM variants: server
* OpenJDK target: OS: linux, CPU architecture: x86, address length: 64

Tools summary:
* Boot JDK: openjdk version "1.8.0-internal" OpenJDK Runtime Environment (build 1.8.0-internal-openjdk_2014_10_31_05_05-b00) OpenJDK 64-Bit Server VM (build 25.20-b23, mixed mode) (at /usr/local/jvm/openjdk-1.8.0-internal)
* Toolchain: gcc (GNU Compiler Collection)
* C Compiler: Version 4.8.2 (at /bin/gcc)
* C++ Compiler: Version 4.8.2 (at /bin/g++)

Build performance summary:
* Cores to use: 7
* Memory limit: 11753 MB

WARNING: Your build output directory is not on a local disk.
This will severely degrade build performance!
It is recommended that you create an output directory on a local disk,
and run the configure script again from that directory.
[openjdk@e583ed8a4e04 jdk9]$ make images
Running make as '/bin/gmake -s VERBOSE=-s LOG_LEVEL=warn -R -I /home/openjdk/jdk9/make/common -s SPEC=/home/openjdk/jdk9//build/linux-x86_64-normal-server-release/spec.gmk'
Building OpenJDK for target 'images' in configuration 'linux-x86_64-normal-server-release'
.............................................................................cut for brevity..........................................................................
## Finished verify-modules (build time 00:00:08)

----- Build times -------
Start 2014-11-01 05:23:08
End 2014-11-01 05:30:34
00:00:08 verify-modules
00:07:26 TOTAL
-------------------------

Finished building OpenJDK for target 'images'
[openjdk@e583ed8a4e04 jdk9]$ build/linux-x86_64-normal-server-release/images/j2sdk-image/bin/java -version
openjdk version "1.9.0-internal"
OpenJDK Runtime Environment (build 1.9.0-internal-openjdk_2014_11_01_05_15-b00)
OpenJDK 64-Bit Server VM (build 1.9.0-internal-openjdk_2014_11_01_05_15-b00, mixed mode)


ClearOS 6 non-privileged user root access

by Sunny Chan


Posted on Wednesday October 17, 2012 at 11:16pm in Linux


Just to save myself searching for this information again:


In ClearOS 6 (a CentOS clone with nicer WebUI), user cannot access shells and by default you can't modify the settings within the WebUI. In order to enable user shell login, you will need to install "app-shell-extension-core.noarch" package.


Trouble compiling OpenJDK 7 in Fedora 18?

by Sunny Chan


Posted on Wednesday July 18, 2012 at 03:38pm in Anything


You will need to modify jdk/make/common/shared/Compiler-gcc.gmk and remove -mimpure-text from the GCC command line. See the icedtea changeset here: http://icedtea.classpath.org/hg/icedtea6?cmd=changeset;node=ddca483b3ed9


Synology LDAP server and Centos 6 client: Brain Dump

by Sunny Chan


Posted on Thursday April 26, 2012 at 09:06pm in Anything


This is a brain dump on how to get Centos 6 client to authenticate using Synology's Directory Service. I have assumed that you have setup the Directory Server correctly.


You need the following packages:



  • openldap-clients

  • sssd


sssd seems to be installed by default, but openldap wasn't.


Run system-config-authenticate, with the following settings:



  • LDAP Search Base DN can be found under Synology Directory Server application

  • Make sure you use ldaps:// in order to use LDAP passwd. Notice that ldaps is switch on by default on synology server.


Then, Apply the changes.


Notice that the SSL certificate used by the LDAP server is a self-generated one, and I didn't manage to change it so I took a short cut and ask openldap client not to borther checking the certifiacte. You can do this by modifying /etc/openldap/ldap.conf and add "TLS_REQCERT allow". This would ask openldap to ignore any SSL cert error.


Once you have done that, try login via ssh and you should be able to access the user listed in the synology server directory. If you want to use the uid and gid from ldap server instead of the passwd file on the Linux client, make sure you swap the priority for passwd in nsswitch.conf.


 


Java SE Embedded and Synology Diskstation

by Sunny Chan


Posted on Tuesday December 13, 2011 at 10:52pm in Anything


I have got a Synology DS209 at home, which is an ARM based NAS. Oracle has released Java SE Embedded 7 and it has got ARMv5 support, so naturally I would want to see whether my NAS is up to it:



disk> uname -a
Linux disk 2.6.32.12 #1955 Sat Nov 26 14:50:54 CST 2011 armv5tel GNU/Linux synology_88f6281_209
disk> java -version
java version "1.7.0_02"
Java(TM) SE Runtime Environment for Embedded (build 1.7.0_02-b13, headless)
Java HotSpot(TM) Client VM (build 22.0-b10, mixed mode)


So "Hello World" is working. Let's try something more fun - like running jetty:


disk> java -jar start.jar
2011-12-14 03:33:21.810:INFO:oejs.Server:jetty-8.0.4.v20111024
2011-12-14 03:33:22.039:INFO:oejdp.ScanningAppProvider:Deployment monitor /volume1/homes/schan/jetty-distribution-8.0.4.v20111024/webapps at interval 1
2011-12-14 03:33:22.075:INFO:oejdp.ScanningAppProvider:Deployment monitor /volume1/homes/schan/jetty-distribution-8.0.4.v20111024/contexts at interval 1
2011-12-14 03:33:22.096:INFO:oejd.DeploymentManager:Deployable added: /volume1/homes/schan/jetty-distribution-8.0.4.v20111024/contexts/javadoc.xml
2011-12-14 03:33:22.413:INFO:oejd.DeploymentManager:Deployable added: /volume1/homes/schan/jetty-distribution-8.0.4.v20111024/contexts/test.xml
2011-12-14 03:33:22.845:INFO:oejw.WebInfConfiguration:Extract jar:file:/volume1/homes/schan/jetty-distribution-8.0.4.v20111024/webapps/test.war!/ to /tmp/jetty-0.0.0.0-8080-test.war-_-any-/webapp
2011-12-14 03:33:30.509:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/,file:/tmp/jetty-0.0.0.0-8080-test.war-_-any-/webapp/},/volume1/homes/schan/jetty-distribution-8.0.4.v20111024/webapps/test.war
2011-12-14 03:33:30.510:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/,file:/tmp/jetty-0.0.0.0-8080-test.war-_-any-/webapp/},/volume1/homes/schan/jetty-distribution-8.0.4.v20111024/webapps/test.war
2011-12-14 03:33:30.510:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/,file:/tmp/jetty-0.0.0.0-8080-test.war-_-any-/webapp/},/volume1/homes/schan/jetty-distribution-8.0.4.v20111024/webapps/test.war
2011-12-14 03:33:30.518:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/,file:/tmp/jetty-0.0.0.0-8080-test.war-_-any-/webapp/},/volume1/homes/schan/jetty-distribution-8.0.4.v20111024/webapps/test.war
2011-12-14 03:33:30.518:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/,file:/tmp/jetty-0.0.0.0-8080-test.war-_-any-/webapp/},/volume1/homes/schan/jetty-distribution-8.0.4.v20111024/webapps/test.war
2011-12-14 03:33:31.338:INFO:oejhs.SslContextFactory:No keystore or trust store configured.  ACCEPTING UNTRUSTED CERTIFICATES!!!!!
2011-12-14 03:33:32.929:INFO:oejs.TransparentProxy:TransparentProxy @ /javadoc-proxy to http://download.eclipse.org/jetty/stable-8/apidocs
2011-12-14 03:33:33.047:INFO:oejs.AbstractConnector:Started [email protected]:8080 STARTING

I am very impressed - They also have the server VM for ARMv7 too - maybe it's time to get a new Diskstation!




Blog upgraded

by Sunny Chan


Posted on Tuesday December 13, 2011 at 10:34pm in Java


I have upgraded this website to:



  • Apache Roller 5.0

  • Apache TOmcat 6.0.35

  • Java 7 Update 2


Let's see how this goes!


More OpenJDK compile notes for Fedora 16

by Sunny Chan


Posted on Saturday November 12, 2011 at 05:01am in Anything


Just to save people from scratching their heads - if you try and compile OpenJDK from vanilla source bundle (not IcedTea) on Fedora 16, you migth see libjvm.so fails to link with a message:


libstdc++ not found


If you look at OpeJDK build readme:


This is caused by a missing libstdc++.a library. This is installed as part of a specific package (e.g. libstdc++.so.devel.386). By default some 64-bit Linux versions (e.g. Fedora) only install the 64-bit version of the libstdc++ package. Various parts of the JDK build require a static link of the C++ runtime libraries to allow for maximum portability of the built images.


 DOH! So what you will need on Fedora 16 is libstdc++-static package


OpenJDK compile problem on Ubuntu 11.10, and the fix

by Sunny Chan


Posted on Friday October 28, 2011 at 10:45am in Java


If you have following the OpenJDK build Readme and try to compile OpenJDK on Ubuntu 11.10, you may see this error: 


/home/schan/openjdk7/build/linux-amd64/tmp/sun/javax.sound/jsoundalsa/obj64/PLATFORM_API_LinuxOS_ALSA_PCM.o: In function `DAUDIO_GetFormats':
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x1fd): undefined reference to `snd_pcm_format_mask_malloc'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x20a): undefined reference to `snd_pcm_close'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x225): undefined reference to `snd_pcm_hw_params_malloc'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x236): undefined reference to `snd_pcm_hw_params_get_format_mask'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x246): undefined reference to `snd_pcm_format_mask_free'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x259): undefined reference to `snd_pcm_hw_params_any'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x26a): undefined reference to `snd_pcm_hw_params_get_format_mask'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x277): undefined reference to `snd_pcm_hw_params_get_channels_min'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x288): undefined reference to `snd_pcm_hw_params_get_channels_max'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x2cf): undefined reference to `snd_pcm_format_mask_test'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x45d): undefined reference to `snd_pcm_hw_params_free'
/home/schan/openjdk7/build/linux-amd64/tmp/sun/javax.sound/jsoundalsa/obj64/PLATFORM_API_LinuxOS_ALSA_PCM.o: In function `setStartThresholdNoCommit':
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x48c): undefined reference to `snd_pcm_sw_params_set_start_threshold'
/home/schan/openjdk7/build/linux-amd64/tmp/sun/javax.sound/jsoundalsa/obj64/PLATFORM_API_LinuxOS_ALSA_PCM.o: In function `setStartThreshold':
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x4bf): undefined reference to `snd_pcm_sw_params'
/home/schan/openjdk7/build/linux-amd64/tmp/sun/javax.sound/jsoundalsa/obj64/PLATFORM_API_LinuxOS_ALSA_PCM.o: In function `setHWParams':
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x518): undefined reference to `snd_pcm_hw_params_any'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x531): undefined reference to `snd_pcm_hw_params_set_access'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x544): undefined reference to `snd_pcm_hw_params_set_format'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x557): undefined reference to `snd_pcm_hw_params_set_channels'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x58a): undefined reference to `snd_pcm_hw_params_set_rate_near'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x5dc): undefined reference to `snd_pcm_hw_params_set_buffer_size_near'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x60b): undefined reference to `snd_pcm_hw_params_set_period_time_near'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x61b): undefined reference to `snd_pcm_hw_params'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x647): undefined reference to `snd_pcm_hw_params_set_periods_near'
/home/schan/openjdk7/build/linux-amd64/tmp/sun/javax.sound/jsoundalsa/obj64/PLATFORM_API_LinuxOS_ALSA_PCM.o: In function `setSWParams':
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x67e): undefined reference to `snd_pcm_sw_params_current'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x6b4): undefined reference to `snd_pcm_sw_params_set_avail_min'
PLATFORM_API_LinuxOS_ALSA_PCM.c:(.text+0x6c4): undefined reference to `snd_pcm_sw_params'


Don't panic - it looks like the Java's linking sequence for ALSA sound library is wrong. Just use this patch:


--- old/make/javax/sound/jsoundalsa/Makefile    2011-10-28 02:28:00.000000000 -0400
+++ new/make/javax/sound/jsoundalsa/Makefile    2011-10-28 02:28:00.000000000 -0400
@@ -65,7 +65,7 @@
        $(MIDIFILES_export) \
        $(PORTFILES_export)
 
-LDFLAGS += -lasound
+EXTRA_LIBS += -lasound
 
 CPPFLAGS += \
        -DUSE_DAUDIO=TRUE \


You should be good to go!


My COSCUP talk on OpenJDK 7

by Sunny Chan


Posted on Thursday September 15, 2011 at 08:54pm in Java



How to compile OpenJDK on Windows

by Sunny Chan


Posted on Sunday July 24, 2011 at 08:42pm in Java


These are the steps that I have made OpenJDK to compile on Windows platform:




  1. Install Visual C++ 2010 Express (or if you are rich, get Visual Studio 2010 Professional) 

  2. Install Windows 7 Platform SDK

  3. Install Cygwin, install the packages suggested on OpenJDK Readme. Also install gcc for step 5

  4. Install DirectX 9.0 SDK

  5. The gnu make package in the current cygwin does not support Windows directory convention and you should compile your own version of the make 3.82 which has the correct support.

  6. Download latest Freetype


    • Compile it using Visual C++ - you can find the Visual C++ project file under <freetype src>/builds/win32/vc2010. 

    • Make sure you have change the type of DLL it generates by going to Project->Properties, then Configuration Manager... button, set it to Release and Win32

    • Make sure you have set it so that it builds a DLL - you can find that under Project->Properties, Configuration Properties, General and there should be a Configuration Type drop down box

    • You can then build freetype. The DLL generated will have a version number attached to it (e.g. freetype245.dll) and you will need to make sure you rename it to freetype.dll.


  7. Get latest Apache ANT

  8. Make sure you have a Java 6 JDK installed

  9. Download the openjdk source code, either using hg or source bundle (I will assume you put it in c:\openjdk)

  10. Open a command prompt for Windows SDK by going to Start -> Windows SDK 7.1 -> Windows SDK 7.1 command prompt

  11. For 32bit ONLY, you should run the Visual Studio compiler settings batch file: c:\program files\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat

  12. Make sure you have override the standard cygwin bin path so that make.exe you have compiled in step 5 take precedent of the default cygwin.

  13. Also check that the link.exe you run in the path is the actual Microsoft linker and not the cygwin's link command - you will need to fiddle with the path.

  14. Setup a number of environment variables:


    1. ALT_BOOTDIR should point to the Java 6 JDK (Step 8)

    2. ALT_DXSDK_PATH is the DirectX SDK PATH (Step 4)

    3. ALT_FREETYPE_LIB_PATH and ALT_FREETYPE_HEADERS_PATH.

    4. ANT_HOME

    5. HOTSPOT_BUILD_JOBS if you want to parallelize your build - you can't use -j options in the make command

    6. ALLOW_DOWNLOADS=true so that it can download JAXP and JAXS jar

    7. Make sure the path is setup correctly (Step 12/13)


  15. You are ready to give it a go. First, run "make sanity" and see whether there is anything you setup incorrectly. If something is wrong, fix it.

  16. If you have passed make sanity, you can run make to build the JDK! Go and make a cuppa, it will take a while. On my i7-2600 and hard drive it took 2 hours.


Important: In order to build a 32bit JDK you must use a 32bit System - ie. you cannot cross compile (ie. 64bit Windows and compile a 32bit JDK)



Let me know whether it works for you. if it doesn't tell me what's wrong and I will fix the instructions!