Recommended way to force MobileFirst-CLI to use Java 6?

554 views Asked by At

I'm on OS X and have been using Java 1.8 from Oracle. In order to install mfp I did have to install the old Java 6 from Apple, but it also seems certain mfp commands, mfp build at least, fail unless I change my JAVA_HOME environment variable to point to the Java 6 installation.

Here's the output I see:

$ mfp build
[Error: 
BUILD FAILED
/Applications/IBM/MobileFirst-CLI/mobilefirst-cli/node_modules/generator-worklight-server/lib/build.xml:133: The following error occurred while executing this line:
/Applications/IBM/MobileFirst-CLI/mobilefirst-cli/node_modules/generator-worklight-server/lib/build.xml:155: Class not found: javac1.8

Total time: 1 second]
Error: Sorry an error has occurred. Please check the stack above for details.
$ JAVA_HOME=/Library/Java/Home mfp build
All apps and adapters were successfully built.
$

What's the best way for me to override JAVA_HOME for mfp? Should I edit /Applications/IBM/MobileFirst-CLI/mfp?

(FYI, the "javac1.8 class not found" error is a known problem with Ant < 1.9, which I assume is bundled with the MobileFirst-CLI as I have Ant 1.9.4 on my system with my Java 1.8 installation.)

2

There are 2 answers

0
Karl Bishop On BEST ANSWER

The best approach here is to have a simple wrapper script as mentioned previously. This keeps you safe from updates. Also, be sure to remove the PATH setting in "/etc/profile". Its quite simple...

In Bash:

#!/bin/bash
#--------------------------------------------------------------------
# Simple multi-MFP launcher script
# Karl Bishop <[email protected]>
#--------------------------------------------------------------------

#-- Set specific Java Runtime?
#export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home

#-- MFP Home directory for custom runtimes
MFP_HOME="${HOME}/dev/mobilefirst"

#-- Set specific Java Runtime
export PATH=$JAVA_HOME/bin:$PATH
echo "Using Java: ${JAVA_HOME}"

#-- Launch custom MFP
${MFP_HOME}/mobilefirst-cli/bin/mobilefirst-cli.js $@

In node...

#!/usr/bin/env node
//--------------------------------------------------------------------
// Simple multi-MFP launcher script
// Karl Bishop <[email protected]>
//--------------------------------------------------------------------
var spawn  = require('child_process').spawn;
var MFP_HOME = process.env.HOME + "/dev/mobilefirst",
    MFP_CMD = MFP_HOME+"/mobilefirst-cli/bin/mobilefirst-cli.js",
    JAVA_HOME = "/Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home";

process.env['JAVA_HOME'] = JAVA_HOME;
process.env['PATH']      = JAVA_HOME+"/bin:" + process.env['PATH'];
console.log("Using Java:", CFG.JAVA_HOME);        //-- Launch custom MFP
spawn( MFP_CMD, args, { stdio:'inherit' } );

Hope this helps.

4
Idan Adar On

Worklight/MFP up to version 7.0 does not support Java 8 at this time. Either Java 6 or 7 must be used.
Thus the recommended way is to uninstall Java 8 and install either Java 6 or 7.

If you want to 'force' MFP use a different Java version, set that Java version in your JAVA_HOME variable.

I have it set in ~/.bash_profile like this:

#### ORACLE JAVA
#export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home"