7

I want to run batch file (similar to Windows) on Mac OS X to run a jar file, after search I found it run batch script.

I am not getting proper link from where I can take help. How can I create this?

5
  • just re-write that .bat file to .sh file, if it is not complex – Thai Tran Jan 29 '13 at 10:49
  • You have at least 3 options to consider on the Mac: shell scripts, Applescript programs, or Automator scripts. They all have their various advantages and disadvantages. – High Performance Mark Jan 29 '13 at 10:50
  • Does this app. have a GUI? If so, there are far better alternatives than scripts to start it up. – Andrew Thompson Jan 29 '13 at 11:12
  • @AndrewThompson Yes my app have GUI. – Neelam Sharma Jan 29 '13 at 13:06
  • OK. Well using a batch file to launch it is less than optimal. This question is asked and answered. I suggest you ask another question "How to launch (easy for user) a Java GUI on multiple platforms?" – Andrew Thompson Jan 29 '13 at 13:11
19

You could create a shell script and run it with Terminal.

For example:

#!/bin/sh
java -jar path/to/jar/file.jar

To run it you need to set up the right user permission, so do chmod u+x script-name then run with ./script-name

1
  • 1
    @Sam Thanks, I tried similar command before posting this, but that time I was trying with rtf file (I am changing its extension to sh), so unable to run shell script. Now tried with txt file, I was able to run. – Neelam Sharma Jan 29 '13 at 10:58
2

You have to create a shell script on MAC OS to get the same result as with a batch file on Windows.

A shell script could look like this:

#!/bin/bash
/opt/java/jre-7x/bin/java -jar /your/path/to/jar-file

Please note that the path to the java executable depends on your java installation directory.

2

You can't run a batch file, but you can run a shell script which is the equivalent on unix based systems.

Like the batch file, the shell script is also platform specific, but should work on Unix and Linux based systems.

0

you CAN'T , because its language specific.

you need to write shell script (or manually matching the windows commands with unix/mac os x commands)

0

Batch files are Windows-only. However it should be easy to convert that batch file to a unix shell script. You find a guide on how to use shell scripts on https://developer.apple.com/library/mac/#documentation/opensource/conceptual/shellscripting/Introduction/Introduction.html

-1

Wine for Mac OS X

This would run windows programs on Mac OS X, try this and let me know.

2
  • 1
    This is likely hugely overkill / fragile if the bat file can be ported to a shell script easily (or written in Java itself.) – Michael Berry Jan 29 '13 at 10:53
  • not that much, but i only posted so he/she could do it easily. – Mohsin Javed Cheema Jan 29 '13 at 10:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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