I have created a .pkg installer for mac using pkgbuild and product build. Is there a way to bundle java jdk 8 along with the package. Say newer version of java is already installed on Mac and my application is compatible with jdk 8 only. Is there a way that bundled jdk can be put locally for that application ONLY without affecting the newer version of jdk already installed?
You can unzip OpenJDK 8 into a non-system folder (or folder of your application) and use it without affecting other already installed JDKs. There is no need for an installation or modification of global environment variables. Therefore, technically it is not a problem.
Note: Oracle's (not open) JDK has different rules regarding installation and distribution.
If starting your application produces an error:
Error: could not find libjava.dylib Failed to GetJREPath()
This means it uses a JDK native library directly. (See bugs.openjdk.java.net/browse/JDK-8213362 for more information.) In order to solve this either:
-vm /Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home
as described in eclipse.org/forums/index.php/t/1102885or:
$JAVA_HOME
in a script for your app.