title: How to create an AppleScript- or Command-file to launch a Java application on Mac OS?
body: <p>I created a Java application and need to prepare it to run on any OS. For Windows I created a batch file like this <code>launch-win32.bat</code>:</p>
  
  <pre><code>@echo off
  javaw -Xss1024k -Xmn256m -Xms512m -Xmx1024m -cp lib/*;bin/myjar-latest.jar my.package.MyMainClass
  </code></pre>
  
  <p>For linux I created a shell script like this <code>launch-linux.sh</code>:</p>
  
  <pre><code>#!/bin/sh
  java -Xss1024k -Xmn256m -Xms512m -Xmx1024m -cp lib/*:bin/myjar-latest.jar my.package.MyMainClass
  </code></pre>
  
  <p>Now I thought MacOS will be quite similar to linux as both are unix based and I asked a friend with a mac to try to run the shellscript to launch my application. But it failed with the following <code>NoClassDefFoundError</code>:</p>
  
  <pre><code>Exception in thread "main" java.lang.NoClassDefFoundError: my/package/MyMainClass
  Caused by: java.lang.ClassNotFoundException: my.package.MyMainClass
      at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
  </code></pre>
  
  <p>It looks like the syntax of the java command is not correct as the classpath is not properly added to the java programm. My main problem now is the following:</p>
  
  <ol>
  <li>MacOS is not officially supported by Sun/Oracle that's why it's difficult to find some good documentation. (I need the latest JRE 7).</li>
  <li>I never used any Mac or don't have any to try out how it could work.</li>
  </ol>
  
  <p>So my questions are now:</p>
  
  <ol>
  <li>How to run java from command line in MacOS, what's the correct syntax? Or why does the command above not work? (For example the main difference between Windows and Linux is using semicolon <code>;</code> instead of colon <code>:</code> separator for the classpath.)</li>
  <li>How should a MacOS script file should be named? <code>.sh</code> or <code>.scpt</code> or  <code>.command</code> or is it like in linux that the file ending doesn't matter as long as you <code>chmod +x</code> the script file?</li>
  </ol>
  
  <p>Thanks for any hints.</p>