6

I have a jar file that is meant to be ran through the command line.

I am not planning to do any java development on the machines where the application will run and my thought process is that therefore I should only need the JRE and not the JDK. In addition, the JDK is like 4x as big as the JRE and I would like to not have to download it.

When installing the JRE on a Mac, it does not set the path for the java command and if I try to run it, osx prompts me to install the JDK.

I wonder if anyone could provide some insight as to how to use the java command in a mac without having the download the bigger sized JDK?

Thanks a lot.

4
  • You can either fully qualify the java executable path, or add the JRE_DIR/bin to your path. Commented Jun 11, 2015 at 15:21
  • Are you trying to run it through Terminal or by double-clicking the jar? Does the application use the console to print/read? Commented Jun 11, 2015 at 15:24
  • It has no UI, it is meant to be ran through the terminal or started by another process. Commented Jun 11, 2015 at 15:29
  • Did you try to run it using /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java? Commented Jun 11, 2015 at 15:33

1 Answer 1

8

Have you tried running this in terminal?

java -jar MyJarName.jar 

However, you can also try and make a runnable application of the jar file. Take a look at Packaging a Java App for Distribution on a Mac

EDIT: You can also try running your starter class from the terminal. cd to the bin folder of your project, then java packageName.className. For example, java my.package.Starter.

Sign up to request clarification or add additional context in comments.

3 Comments

yes, it prompts to install the JDK if I try to use the java command. Will read your link now.
The command java without full path is only available on Macs if the JDK has been installed on them.
This is correct. I just had to find the path to the executable. You can find it if you go to System Preferences > Java > Java (tab) > View... > Path For me it was: /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.