1

The question is how do I run some application written in java and bundled into .app package from command-line?

The main purpose of this is to run an application under JDK7. So I will start it with the java bundled in JDK7 instead of default one.

I need something like https://apple.stackexchange.com/a/10253/15553 but with java, so I can run it with a different JDK.

  • You're better of using a *.jar, then a *.app. App bundles are made specifically for objective-c/c/c++ and so on. You might be able to create a makeshift app, but that would be pointless because you would have to run it manually anyway – rubixibuc Feb 17 '12 at 7:16
  • $Java /Applications[...]/*.app/[...]/java-executable Is this what you mean? Because from my experience this won't work. – rubixibuc Feb 17 '12 at 7:21
  • You're best option is creating an app package that launches the java app using c, using the exec family of functions – rubixibuc Feb 17 '12 at 7:22
  • @rubixibuc I have NetBeans.app. And I need to run it under JDK7. Is the any way of doing in except for making /usr/bin/java to point a java binary in JDK7 bundle? – Uko Feb 17 '12 at 7:40
  • 1
    Maybe I'm misunderstanding, but what I would do if you know c or objective-c, is just have the binary launch the file with exec(). linux.die.net/man/3/exec – rubixibuc Feb 17 '12 at 7:52
1

To switch to another JVM, try to modify the JAVA_HOME and PATH shell environment variable in ~/.profile.

# in ~/.profile
# switch to another JVM (here, 1.7)
unset JAVA_HOME PATH
export JAVA_HOME="$(/usr/libexec/java_home -F --version 1.7 2>/dev/null)"
export PATH="${JAVA_HOME}/bin:${PATH}"

# general info on Java preferences
open -a 'Java Preferences'
  • It's a nice idea. But I'm looking for a solution to run just one app with a different java. Thou making the script that will switch java, launch app and switch if back is also an option. Anyway the problem is solved because Netbeans unix-executable binary allows to set a home of JDK as a parameter. But the question is still interesting, and you have pointed out the best working solution this far. – Uko Feb 17 '12 at 17:18
1

Or open the .app file and edit or add the JVMVersionvalue in the Info.plist like so

<key>JVMVersion</key>
<string>1.6+</string>
  • Not working. Neither 1.6+ nor 1.7+ – Uko Feb 17 '12 at 17:23
  • 1
    Maybe you are missing some other Java Keys there. Have a look at this Link – m0rth1um Feb 17 '12 at 18:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .