Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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 http://apple.stackexchange.com/a/10253/15553 but with java, so I can run it with a different JDK.

share|improve this question
    
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

2 Answers 2

up vote 1 down vote accepted

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'
share|improve this answer
    
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

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

<key>JVMVersion</key>
<string>1.6+</string>
share|improve this answer
    
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 –  morth Feb 17 '12 at 18:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.