Java-gcj in Gentoo/Alpha

"Jose Luis Rivero (YosWinK)" <[email protected]>
Newsgroups gmane.linux.gentoo.java
Message-ID <[email protected]>
Hi *:

These days I was playing with java-gcj to bring a java environment to 
Gentoo/Alpha Linux users. Gentoo/Alpha currently lacks of any kind of 
java support since most of the usual providers (sun, blackdown and 
company) don't work in alpha.

I tested the gcj-4.3* but it gives an internal compiler error which need 
a bit more of love (probably I will work on this in the next days).

Using gcj-4.2 from the java-gcj-overlay and patches from debian/fedora 
was quite easy to have a jre/jdk 1.4 working and be able to compile and 
run tomcat. I want to thanks geki for the all the support.

Some patches and changes were needed so I want to discuss them with the 
people involved in Gentoo java-gcj. The patches aren't related to alpha, 
maybe some of them could be useful.

My knowledge of java is nearly zero so, please, if something is 
completely wrong, excuse me.

Here we go:

========================
1. Bump gcj-4.2_alpha to gcj-4.2.1 (and gcj-jdk)

Bumping the version of gcj to 4.2.1 from 4.2_alpha was as trivial as 
copy the ebuild. Probably I can give it a try in x86 but anyway, I think 
that we can keep the new version only keyworded for alpha if needed.

========================
2. sun-javamail

Problem:
The ebuild claims to need DEPEND jdk-1.5 (related to bug #157488) but 
the official page faq said is enough with 1.4. I was able to compile it 
with my gcj-4.2.1 so probably the dependency on 1.5 is not mandatory (at 
least using gcj).

Fix:
Create the package in then gcj overlay and change DEPEND 1.5 by 1.4 .

========================
3. mx4j-core

Problem:
mx4j won't compile since -iiop is not supported by gcj.

Fix:
Support m4xj in the gcj overlay and use a patch from fedora to remove 
the need of this support when using gcj.
  * (patch no-iiop-gcj-support.patch attached)

========================
4. commons-daemon

Problem:
During the compiling process it didn't found jni.h. Problem was in 
configure.in which set the include path to "$JAVA_HOME/include" (which 
points to "/usr/lib/jvm/gcj-jdk-4.2/include" probably following the 
symlink "/etc/java-config-2/current-vm/").

The proper path for jni.h is 
"/usr/lib/gcj-4.2.1/lib/gcc/alphaev68-unknown-linux-gnu/4.2.1/include/".

Fix:
Not a fix, more a workaround. Include by hand in the configure.in the 
proper path to the jni.h gcj dir. The path is hardcoded in my patch 
which really sucks. Probably need to be tweaked, not very sure how.

========================
5. tomcat

Problem 1:
tomcat-5.5 depends upon dev-java/eclipse-ecj-3.2 while I used the next
version 3.3.

Fix 1:
-RDEPEND="=dev-java/eclipse-ecj-3.2*
+RDEPEND=">=dev-java/eclipse-ecj-3.2

==

Problem 2:
tomcat-5.5 use hardcoded eclipse-ecj-3.2 in calls to java-pkg_getjar 
while I used eclipse-ecj-3.3.

Fix 2:
Not very sure about how to detect properly the version of eclipse-ecj 
and use it inside the ebuild (eclass variable?). Probably up to the 
maintainer.

==

Problem 3:
It won't compile because it lacks of sun.ssl clasess.

Fix 3:
Patch from fedora to change to the proper classes.
  * (patch tomcat-javaxssl.patch attached)

==

Problem 4:
Tomcat won't start because it can't find LoggingManager classes.

Fix 4:
Tweak tomcat.init2 to not include the PATH to loggingManager. Patch from 
Debian.
  * (a patched tomcat.init.2 is attached)

==

Problem 5:
Catalina.sh need to be patched since the logging and security manager 
are not supported in gcj.

Fix 5:
Disable the JAVA_OPTS which enable the logging class and make a warning 
if the security manager is enable.
  * (patch gcj-catalina.sh.patch attached)


Comments? Feedback? Destructive criticism?

Thanks.

-- 
Jose Luis Rivero [[email protected]]
Gentoo/Doc Gentoo/Alpha
gcj-catalina.sh.patch (text/plain, 1.3 KB)
--- container/catalina/src/bin/catalina.sh.orig	2007-03-05 15:27:41.000000000 +0000
+++ /container/catalina/src/bin/catalina.sh	2007-08-10 17:44:47.000000000 +0000
@@ -161,10 +161,12 @@
   JAVA_ENDORSED_DIRS=`cygpath --path --windows "$JAVA_ENDORSED_DIRS"`
 fi
 
+# Fix gcj. See debian patches no LogManager is ready for gcj
+
 # Set juli LogManager if it is present
-if [ -r "$CATALINA_HOME"/bin/tomcat-juli.jar ]; then
-  JAVA_OPTS="$JAVA_OPTS "-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager" "-Djava.util.logging.config.file="$CATALINA_BASE/conf/logging.properties"
-fi
+#if [ -r "$CATALINA_HOME"/bin/tomcat-juli.jar ]; then
+#  JAVA_OPTS="$JAVA_OPTS "-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager" "-Djava.util.logging.config.file="$CATALINA_BASE/conf/logging.properties"
+#fi
 
 # ----- Execute The Requested Command -----------------------------------------
 
@@ -204,6 +206,12 @@
   else
     shift
     if [ "$1" = "-security" ] ; then
+      # FIx for gcj
+      echo "The java-gcj-compat-dev environment currently doesn't support"
+      echo "a security manager. Please check the TOMCAT5_SECURITY variable"
+      echo "in /etc/default/tomcat5.5."
+      exit 1
+      
       echo "Using Security Manager"
       shift
       exec "$_RUNJDB" $JAVA_OPTS $CATALINA_OPTS \
tomcat.init.2 (text/plain, 3.6 KB)
#!/sbin/runscript
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/www-servers/tomcat/files/5.5/tomcat.init.2,v 1.6 2007/05/20 23:24:56 wltjr Exp $

init_env_vars() {
	if [ "$(gjl -p tomcat-5.5 --get-vm)" ] ; then
		eerror "Tomcat has been compiled with java5 USE flag set."
		eerror "Tomcat now requires a VM >=1.5 to run."
		eerror "Please check your VM version, and restart Tomcat."
		eend 1
	fi

	# Populate JAVA_HOME
	JAVA_HOME=`java-config --jre-home`

	# Set some sane defaults
	if [ -z "${CATALINA_TMPDIR}" ] ; then
		CATALINA_TMPDIR="${CATALINA_BASE}"/temp
	fi
	JPDA_TRANSPORT=${JPDA_TRANSPORT:="dt_socket"}
	JPDA_ADDRESS=${JPDA_ADDRESS:="8000"}
	JPDA_OPTS=${JPDA_OPTS="-Xdebug -Xrunjdwp:transport=${JPDA_TRANSPORT},address=${JPDA_ADDRESS},server=y,suspend=n"}

	# Activate Logging
	# FIX - gcj Disable reason: Debian #399251 

	#if [[ -r "${CATALINA_HOME}"/bin/tomcat-juli.jar ]]; then
	#	JAVA_OPTS="${JAVA_OPTS} -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager \
	#		-Djava.util.logging.config.file=${CATALINA_BASE}/conf/logging.properties"
	# fi

	# Populate the classpath
	CLASSPATH="${CLASSPATH}:${CATALINA_HOME}/server/lib:${JAVA_HOME}/lib/tools.jar"
	if [ -n "${JSSE_HOME}" ]; then
		CLASSPATH="${CLASSPATH}:${JSSE_HOME}/lib/jcert.jar:${JSSE_HOME}/lib/jnet.jar:${JSSE_HOME}/lib/jsse.jar"
	fi
	CLASSPATH="${CLASSPATH}:${CATALINA_HOME}/bin/bootstrap.jar:${CATALINA_HOME}/bin/commons-logging-api.jar"

	OPTS_CP="${JAVA_OPTS} ${CATALINA_OPTS} \
			 -Djava.endorsed.dirs=${CATALINA_HOME}/common/endorsed \
			 -classpath ${CLASSPATH}"

	CATALINA_ARGS="-Dcatalina.base=${CATALINA_BASE} \
			-Dcatalina.home=${CATALINA_HOME} \
			-Djava.io.tmpdir=${CATALINA_TMPDIR} \
			org.apache.catalina.startup.Bootstrap "

	if [ ! -f "${CATALINA_BASE}logs/catalina.out" ]; then
		touch "${CATALINA_BASE}logs/catalina.out"
		chown tomcat:tomcat "${CATALINA_BASE}logs/catalina.out"
	fi
}

start_helper() {
	local executor=${1}
	shift
	local arguments="--start --quiet \
		--chdir "${CATALINA_TMPDIR}" \
		--chuid ${CATALINA_USER}:${CATALINA_GROUP} \
		--make-pidfile --pidfile /var/run/tomcat-5.5.pid"
	start-stop-daemon ${arguments} --exec ${executor} -- ${OPTS_CP} "$@" \
		${CATALINA_ARGS} ${TOMCAT_START} >> "${CATALINA_BASE}"/logs/catalina.out 2>&1 &
	return $?
}

depend() {
	use dns logger net
}

start()	{
	ebegin "Starting Tomcat"
	init_env_vars
	# Figure out what arguments to pass start_helper based on TOMCAT_START
	if [ "${TOMCAT_START}" = "debug" ] ; then
		start_helper ${JAVA_HOME}/bin/jdb \
			-sourcepath ${CATALINA_HOME}/../../jakarta-tomcat-catalina/catalina/src/share
	elif [ "${TOMCAT_START}" = "-security debug" ] ; then
		start_helper ${JAVA_HOME}/bin/jdb \
			-sourcepath ${CATALINA_HOME}/../../jakarta-tomcat-catalina/catalina/src/share \
			-Djava.security.manager \
			-Djava.security.policy=${CATALINA_BASE}/conf/catalina.policy
	elif [ "${TOMCAT_START}" = "jpda start" ] ; then
		start_helper ${JAVA_HOME}/bin/java ${JPDA_OPTS}
	elif [ "${TOMCAT_START}" = "start" ] ; then
		start_helper ${JAVA_HOME}/bin/java
	elif [ "${TOMCAT_START}" = "-security start" ] ; then
		start_helper ${JAVA_HOME}/bin/java \
			-Djava.security.manager \
			-Djava.security.policy=${CATALINA_BASE}/conf/catalina.policy
	else
		eerror "Invalid TOMCAT_START variable value, or one is not set"
		eerror "Please see /etc/conf.d/tomcat-5.5 for more information"
		eend 1
	fi
	eend $?
}

stop()	{
	ebegin "Stopping Tomcat"
	init_env_vars
	start-stop-daemon --stop --quiet \
	       	--make-pidfile --pidfile /var/run/tomcat-5.5.pid \
			--exec ${JAVA_HOME}/bin/java -- ${OPTS_CP} ${CATALINA_ARGS} ${STD_OUT} stop
	eend $?
}
tomcat-javaxssl.patch (text/plain, 3.4 KB)
--- connectors/jk/java/org/apache/jk/server/JkMain.java.sav	2006-03-23 16:56:20.000000000 +0100
+++ connectors/jk/java/org/apache/jk/server/JkMain.java	2006-03-23 16:57:27.000000000 +0100
@@ -101,7 +101,7 @@
         return jkMain;
     }
 
-    private static String DEFAULT_HTTPS="com.sun.net.ssl.internal.www.protocol";
+    private static String DEFAULT_HTTPS="javax.net.ssl.internal.www.protocol";
     private void initHTTPSUrls() {
         try {
             // 11657: if only ajp is used, https: redirects need to work ( at least for 1.3+)
--- connectors/util/java/org/apache/tomcat/util/net/jsse/JSSE13SocketFactory.java.sav	2006-03-23 16:58:48.000000000 +0100
+++ connectors/util/java/org/apache/tomcat/util/net/jsse/JSSE13SocketFactory.java	2006-03-23 17:01:34.000000000 +0100
@@ -67,13 +67,13 @@
      */
      void init() throws IOException {
         try {
-            try {
-                Class ssps = Class.forName("sun.security.provider.Sun");
-                Security.addProvider ((Provider)ssps.newInstance());
-            }catch(Exception cnfe) {
+            //try {
+            //    Class ssps = Class.forName("sun.security.provider.Sun");
+            //    Security.addProvider ((Provider)ssps.newInstance());
+            //}catch(Exception cnfe) {
                 //Ignore, since this is a non-Sun JVM
-            }
-            Security.addProvider (new com.sun.net.ssl.internal.ssl.Provider());
+            //}
+            //Security.addProvider (new com.sun.net.ssl.internal.ssl.Provider());
 
             String clientAuthStr = (String)attributes.get("clientauth");
             if("true".equalsIgnoreCase(clientAuthStr) || 
@@ -91,8 +91,8 @@
             if (algorithm == null) algorithm = defaultAlgorithm;
 
             // Set up KeyManager, which will extract server key
-            com.sun.net.ssl.KeyManagerFactory kmf = 
-                com.sun.net.ssl.KeyManagerFactory.getInstance(algorithm);
+            javax.net.ssl.KeyManagerFactory kmf = 
+                javax.net.ssl.KeyManagerFactory.getInstance(algorithm);
             String keystoreType = (String)attributes.get("keystoreType");
             if (keystoreType == null) {
                 keystoreType = defaultKeystoreType;
@@ -102,22 +102,22 @@
                      keystorePass.toCharArray());
 
             // Set up TrustManager
-            com.sun.net.ssl.TrustManager[] tm = null;
+            javax.net.ssl.TrustManager[] tm = null;
             String truststoreType = (String)attributes.get("truststoreType");
             if(truststoreType == null) {
                 truststoreType = keystoreType;
             }
             KeyStore trustStore = getTrustStore(truststoreType);
             if (trustStore != null) {
-                com.sun.net.ssl.TrustManagerFactory tmf =
-                    com.sun.net.ssl.TrustManagerFactory.getInstance("SunX509");
+                javax.net.ssl.TrustManagerFactory tmf =
+                    javax.net.ssl.TrustManagerFactory.getInstance("SunX509");
                 tmf.init(trustStore);
                 tm = tmf.getTrustManagers();
             }
 
             // Create and init SSLContext
-            com.sun.net.ssl.SSLContext context = 
-                com.sun.net.ssl.SSLContext.getInstance(protocol); 
+            javax.net.ssl.SSLContext context = 
+                javax.net.ssl.SSLContext.getInstance(protocol); 
             context.init(kmf.getKeyManagers(), tm, new SecureRandom());
 
             // Create proxy
no-iiop-gcj-support.patch (text/plain, 858 B)
--- mx4j-3.0.1.orig/build/build.xml.orig	2007-08-12 21:42:08.000000000 +0000
+++ mx4j-3.0.1.orig/build/build.xml	2007-08-12 21:50:11.000000000 +0000
@@ -268,11 +268,12 @@
          <patternset refid="rmx4j.classes"/>
          <classpath refid="lib.classpath"/>
       </javac>
+<!--  
       <rmic base="${core.classes.dir}" classname="javax.management.remote.rmi.RMIServerImpl" classpathref="classpath" debug="yes" stubversion="1.2"/>
       <rmic base="${core.classes.dir}" classname="javax.management.remote.rmi.RMIConnectionImpl" classpathref="classpath" debug="yes" stubversion="1.2"/>
       <antcall target="rmic.iiop"/>
       <antcall target="rmic.iiop.poa"/>
-
+-->
       <jar jarfile="${rjmx.jar.file}" manifest="${etc.dir}/MANIFEST.MF">
          <fileset dir="${core.classes.dir}">
             <patternset refid="rjmx.classes"/>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.