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.

  • Welcome to Ask Ubuntu. Does this FAQ Entry help you? – MadMike Dec 5 '13 at 20:54
  • I find it hard to follow that guide. When I added the manifest, the program didn't even run on windows anymore. Do you have any other source / could you write it out for me? I don't understand the part where I have to write the manifest, where it says mypackage.myclass. Would I have to add it like "default package.Mainclass" or would I have to add it like "JavaProject.Mainclass" ? – Bart Dec 5 '13 at 22:11
  • Could their be dll files for the library linked that are compiled for windows? – Ashwin Gupta Jul 12 '17 at 18:40
0

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

  • This doesn't work. As I said the other jar runs fine, I am sure it has something to do with it having an SWT library – Bart Dec 5 '13 at 22:06
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.

  • As I said my other .jar ran perfectly fine. It has something to do with it having the SWT library. – Bart Dec 5 '13 at 22:07
  • you are not getting any error with "javaws" ?? – Sukupa91 Dec 5 '13 at 22:08
  • javaws?! No, I can run the .jar file which displays a simple JButton, but the SWT .jar file did not run. I am sure I have to include the library somehow but I don't understand why it does run on windows but not on linux, while the JButton file runs on both OS'es just fine. – Bart Dec 5 '13 at 22:13
0

You need to call it like this:

java -jar yourfilehere
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)

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.