19

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 .

Community
  • 1
  • 1
juanignaciosl
  • 3,435
  • 2
  • 28
  • 28

5 Answers5

29

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
juanignaciosl
  • 3,435
  • 2
  • 28
  • 28
  • I would expect that the exports should go also to the start hook. correct me if am wrong ! – youssef Aug 25 '14 at 15:41
  • I think it's not necessary, those exports were enough for me. – juanignaciosl Aug 25 '14 at 16:06
  • Is that in a new DIY ? and even after restarting cartridge ? – youssef Aug 25 '14 at 16:11
  • I also needed to add "export OPENSHIFT_WILDFLY_JDK8=$OPENSHIFT_DATA_DIR/jdk1.8.0_31/" into .openshift/action_hooks/pre_start_wildfly – endriju Feb 19 '15 at 01:34
  • 1
    See answer by sathish - the DIY package now includes JDK 1.8, just not on the path by default. – Rafael Chaves Feb 07 '16 at 14:46
  • the only note of caution on the above solution is that if someone using free account, it may very quickly eat up all the disk space and leave one stranded. So sticking to the embedded idk make more sense to save time going forward. – Yoku Nov 16 '16 at 21:17
19

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
  • 2
    I have three places for `action_hooks` which one is the correct one? `./app-root/runtime/repo/.openshift/action_hooks` `./app-deployments/2015-09-23_11-04-35.405/repo/.openshift/action_hooks` `./jbossews/template/.openshift/action_hooks`. Please guide – Ankur Raiyani Feb 18 '16 at 14:50
  • This doesn't work for me. After setting those export I still see that my environment uses OpenJDK, any ideas? – Rafal Spacjer Feb 19 '16 at 07:48
9

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
Alexian
  • 654
  • 6
  • 12
3

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 :)

James Owen
  • 256
  • 1
  • 11
0

The default wildfly 8 (8.2.1) cartridge now supports JDK8 out-of-the-box.

Julien Kronegg
  • 4,968
  • 1
  • 47
  • 60