1

I made the following small file with Eclipse, using the SWT Library:

//all the imports
public class classtest {
    public static void main(String[] args) {

        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setSize(300, 200);
        shell.setText("Button Example");
        //shell.setLayout(new RowLayout());

        Button button = new Button(shell, SWT.PUSH);


        button.setLocation(20,20);
        button.setSize(new Point(70,30));        //new point seems to be optional?
        button.setText("Buttontje ");     

        shell.open ();


        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
            display.sleep();
        }
        display.dispose();
    }
}

The .jar I made out of it runs totally fine on windows.

Now I installed Java on Ubuntu using the following commands (from http://www.ubuntugeek.com/how-to-install-oracle-java-7-in-ubuntu-12-04.html ):

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer

Java seemed to be installed fine. I run the file, but nothing happens. An other program of me, though, using only JButtons and no SWT Library, DOES run.

Do I need to install the SWT library on the target platform to make it work? But how would I install it? I thought the SWT Library would be included in the .jar so that it would run the SWT layout on every platform, as long as java is installed.

Thomas Ward
  • 78,878
Bart
  • 11
  • 1
  • 2

4 Answers4

1

You need to call it like this:

java -jar yourfilehere
0

OK right click the .jar and click properties then click permissions and click allow executing file as program

0

Executing .jar files in linux Ubuntu is little bit different from as that in windows, here as you simply double click on the file it will open it with archive , So try to open it with java. if that did not solves your problem then make sure you have installed java correctly by-

java -version
javac
javaws

If there are no errors move to next part , otherwise install it again after removing completely

For making default executing by java right click on any .jar files and select properties. Click on the 'Open With' tab. select Sun 'Oracle 7 Runtime'. And click close to save the settings.

Sukupa91
  • 3,067
0

I have encountered the same problem.

This answer is 4 years late, but I suggest opening a terminal in the directory that your .jar file resides in, and do:

java -jar "jarfilehere.jar"

Doing this in a terminal, you will most probably get errors on why it didn't run.

(In my case, the JFX classes weren't present)