On OpenBSD4.0 the compilation has been made easier because Kaffe Java is used to bootstrap compilation and not JDK under Linux emulation. Also see instruction in FAQ.
First check which source files that are required to build the JDK.
# cd /usr/ports/devel/jdk/1.5
# make install
Download the source files, patchset etc. and store to /usr/ports/distfiles. For this specific JDK/OpenBSD version the following files must be downloaded.
jdk-1_5_0-src-scsl.zip
jdk-1_5_0-bin-scsl.zip
from http://wwws.sun.com/software/communitysource/j2se/java2/download.html
bsd-jdk15-patches-3.tar.bz2
from http://www.eyesbeyond.com/freebsddom/java/jdk15.html
jdk-1_5_0-solaris-i586.tar.Z
from http://java.sun.com/products/archive/j2se/5.0/index.html
xalan-j_2_7_0-bin.tar.gz
from http://www.apache.org/dist/xml/xalan-j/
Install the following pre-compiled packages to save some compile time.
zip-2.32.tgz
kaffe-1.1.7p2.tgz
mozilla-devel-1.7.13p0.tgz
openmotif-2.1.30.5p1.tgz
An even better way to do the above is to set the followin environment varianbles. This enables all dependent packages to be installed as binaries from your preferred package mirror
PKG_PATH=ftp://ftp.sunet.se/pub/OpenBSD/<ver>/packages/<arch>
FETCH_PACKAGES=Yes
Compile the JDK. This will take several hours.
make build
make install
Your done!
Compile package as described above.
Add packges
# pkg_add zip-2.32.tgz
# pkg_add openmotif-2.1.30.5p1.tgz
# pkg_add jdk-1.5.0p19.tgz
Follow install messages e.g. add the following to man pages.
whatdb /usr/local/jdk-1.7.0/man/whatis.dbdefault /usr/local/jdk-1.7.0/man/ 1 /usr/local/jdk-1.7.0/man/man1