1

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

Community
  • 1
  • 1
N2O
  • 183
  • 7
  • hacking the MFP installation to force it to use Java 6 ... in `/Applications/IBM/MobileFirst-CLI/mobilefirst-cli/bin/mobilefirst-cli.js`, right at the top (immediately after `#!/usr/bin/env node`: `process.env['JAVA_HOME'] = '/Library/Java/Home';` – N2O Jun 09 '15 at 15:28

2 Answers2

3

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 <kfbishop@us.ibm.com>
#--------------------------------------------------------------------

#-- 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 <kfbishop@us.ibm.com>
//--------------------------------------------------------------------
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.

Karl Bishop
  • 251
  • 1
  • 5
0

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"
Idan Adar
  • 44,156
  • 13
  • 50
  • 89
  • Other things need Java 8 ... uninstalling it isn't a solution. How best to make MFP use Java 6 instead? ... All it takes is setting `JAVA_HOME` ... I guess I'll just do a wrapper script for `mfp` – N2O Jun 09 '15 at 15:08
  • I do not think it is possible to set a specific version of Java for a specific app and another version of Java for anything else. At least from Googling. – Idan Adar Jun 09 '15 at 15:29
  • If you find a way - post an answer. – Idan Adar Jun 09 '15 at 15:29
  • the solution is to override `JAVA_HOME` before running the command ... I've done that by hacking `mobilefirst-cli.js` and setting `process.env['JAVA_HOME']` to the path to Java 6 (see my comment on the question) ... I was really hoping there might be a "recommended" solution as this will have to be redone on an upgrade – N2O Jun 09 '15 at 15:35