JDK 8 support at DIY cartridge in OpenShift
I know WildFly cartridge doesn't have JDK support, but can I somehow install Java 8 at experimental DIY cartridge? java-1.7.0 is the latest version available at /usr/lib .
Solution 1:
If you want an specific JDK version you can download it and set the environment variables:
cd $OPENSHIFT_DATA_DIR
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u5-b13/jdk-8u5-linux-x64.tar.gz
tar -zxf jdk-8u5-linux-x64.tar.gz
export PATH=$OPENSHIFT_DATA_DIR/jdk1.8.0_05/bin:$PATH
export JAVA_HOME="$OPENSHIFT_DATA_DIR/jdk/jdk1.8.0_05"
Thanks to this cartridge.
As @youssef points out, you should also add this lines to .openshift/action_hooks/start:
export JAVA_HOME="$OPENSHIFT_DATA_DIR/jdk/jdk1.8.0_05"
export PATH=$OPENSHIFT_DATA_DIR/jdk1.8.0_05/bin:$PATH
UPDATE: now OpenShift has added alternative runtimes, you can skip downloading your own:
export JAVA_HOME=/etc/alternatives/java_sdk_1.8.0
export PATH=$JAVA_HOME/bin:$PATH
Solution 2:
Java 8 is now available by default with DIY. You just need to set PATH as given below in your /.openshift/action_hooks/start.sh
export JAVA_HOME=/etc/alternatives/java_sdk_1.8.0
export PATH=$JAVA_HOME/bin:$PATH
Solution 3:
Hi I want to update the answer above, since I had the same need to update the JDK for my Vert.x application. Since it's totally written in Java8 (Vert.x code looks much better with it) I started to experiment a little with Openshift, until I met the issue that juan reported.
However I had to fix some stuff and updated to JDK1.8u20:
// connect with SSH to your application, then
cd $OPENSHIFT_DATA_DIR
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u20-b26/jdk-8u20-linux-x64.tar.gz
tar -zxf jdk-8u20-linux-x64.tar.gz
export PATH=$OPENSHIFT_DATA_DIR/jdk1.8.0_20/bin:$PATH
export JAVA_HOME=$OPENSHIFT_DATA_DIR/jdk1.8.0_20/
// then depending on your cartridge you need to exec the following command
echo $JAVA_HOME > $OPENSHIFT_{cartridge}_DIR/env/JAVA_HOME
// in my case was
// echo $JAVA_HOME > $OPENSHIFT_VERTX_DIR/env/JAVA_HOME
// for Wildfly I presume it is
// echo $JAVA_HOME > $OPENSHIFT_WILDFLY_DIR/env/JAVA_HOME
Solution 4:
This does not work if you are using Maven with the DIY-Cartridge.
If you look at the mvn command in "/usr/bin/mvn" on your box you will see that mvn resets $JAVA_HOME when executed.
#!/bin/sh
prog=$(basename $0)
export JAVA_HOME=/usr/lib/jvm/java
export JAVACMD=$JAVA_HOME/bin/java
export M2_HOME=/usr/share/java/apache-maven-3.0.4
exec $M2_HOME/bin/$prog "$@"
UPDATE
After a bit of head scratching I was finally able to work out how to run a java8 application using Maven on a DIY cartridge. As we know the mvn executable on usr/bin is no good, we simply download our own. Once we have our own version of Maven which respects JAVA_HOME then we are good to go. Here are my action_hooks...
pre_start
#!/bin/bash
cd $OPENSHIFT_DATA_DIR
#Download Maven If not already installed
if [ ! -d apache-maven-3.3.3 ]; then
wget http://www.eu.apache.org/dist/maven/maven-3/3.3.3/binaries/apache-maven-3.3.3-bin.tar.gz
tar -zxf apache-maven-3.3.3-bin.tar.gz
fi
#Download Java8 If not already installed
if [ ! -d jdk1.8.0_05 ]; then
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u5-b13/jdk-8u5-linux-x64.tar.gz
tar -zxf jdk-8u5-linux-x64.tar.gz
fi
start
export PATH=$OPENSHIFT_DATA_DIR/jdk1.8.0_05/bin:$PATH
export JAVA_HOME="$OPENSHIFT_DATA_DIR/jdk1.8.0_05"
cd $OPENSHIFT_DATA_DIR
echo -e "<settings>\n <localRepository>$OPENSHIFT_DATA_DIR</localRepository>\n</settings>\n" > settings.xml
$OPENSHIFT_DATA_DIR/apache-maven-3.3.3/bin/mvn -f $OPENSHIFT_REPO_DIR/pom.xml clean package -s $OPENSHIFT_DATA_DIR/settings.xml
nohup java -jar $OPENSHIFT_REPO_DIR/target/**YOUR_FAT_JAR**.jar > $LOG 2>&1 &
Hope this helps anyone else who put as many hours in to this as I did :)