2

I've written a Java application with Eclipse that uses SWT for the UI. (see SWT Exception when running jar: Exception in thread "main" org.eclipse.swt.SWTException: Invalid thread access for detail).

I exported as JAR and was having trouble getting it to run from Finder as well as from Terminal. I finally got it to run from Terminal with java -XstartOnFirstThread -jar CommonDenom.jar

I still, however, cannot get it to run when I export as a JAR from eclipse. This is because it needs the argument -XstartOnFirstThread bundled with it when it exports. Then I noticed that in Properties >> Run/Debug Settings >> commonDenom >> Edit >> (x)= Arguments there is a tick-box that says "Use the -XstartOnFirstThread argument when launching with SWT." But it was already checked. So I figured this option only applies when launching the code with Eclipse, and doesn't apply to the exported JAR.

So I added the argument manually to the VM Arguments box in the same tab. When I went to export as a runnable JAR, I noticed a warning that reads "VM arguments will not be part of the runnable JAR. Arguments can be passed on the command line when launching the JAR.

Ultimately, I need a way to get this to launch from finder (be it JAR or otherwise) without having to open Terminal and launch it manually. Yes, I can write a Shell script to launch it, but I feel there must be a simpler way.

Community
  • 1
  • 1
dbconfession
  • 1,147
  • 2
  • 23
  • 36

1 Answers1

2

You have two options. The easy way is to create a shell script:

#!/bin/bash
java -XstartOnFirstThread -jar CommonDenom.jar

The user runs the script, which sets the arguments and runs Java.

The other way is to create an Application Bundle. It include a properties file (Info.plist) where you can set these properties. You can also use Oracle's appbundler tool to create an application bundle.

martinez314
  • 12,162
  • 5
  • 36
  • 63
  • If I create a shell script, do I this in Automator? Or di I just do it in text pad? If I want to bundle it as an app, can I use Automator to create a new Application? Is that the same? And if so, what files/folders and/or actions get included int he workflow? I'm assuming the jar itself, the classes, the manifest, and swt.jar? Then once I save it, how do I edit the plist file to specify what i wanted to do in my original post? – dbconfession Mar 11 '14 at 06:37