Cannot start SWT application in Eclipse

I followed the tutorial that appeared in the Eclipse editor (click Help -> Welcome -> Tutorials ). I worked through all the steps:

This cheat sheet shows how to create a "Hello World" application that uses a set of standard widgets (SWTs). The application will simply show a blank window to the user. If you need help in any, press the button (?) To the right. Let it begin!

If you are not already in the Java perspective, in the main menu, select Window> Open Perspective> Java or click "Click to Run", the link below.

Open the import wizard in the main menu using File> Import ... and choose Plug-in Development> Plugins and Snippets. Click Next. On the Import Plugins and Snippets Page, select Import from: Active Target Platform. Plugins and snippets to import: select from all the plugins and snippets found in the specified location. Import as: Projects with source folders. Click Next. On the Selection page, add org.eclipse.swt. {Platform}. {Os}. {Arch} (ex: org.eclipse.swt.win32.win32.x86 for win32) to the plugins and snippets to import : list. Click β€œFinish." This will create org.eclipse.swt. {platform}. {os}. {arch}, which we will need to compile and run the application.

Now we need a project to store our own source code. Basically a toolbar, click the "Create Java Project" button or click the link below. Enter HelloWorldSWT for the project name, then click Finish.

Since SWT is required for our project, we must indicate this in the project properties. Right-click the project and select Properties. in On the Java Build Path Path page, open the Projects tab, add org.eclipse.swt. {platform}. {os}. {arch}, then click OK.

The next step is to create a new class. On the main toolbar, click the New Java Class button (or the link below). If not already specified, select HelloWorldSWT / src as the source folder. Log in HelloWorldSWT for the class name and check the box to create main (), then click Finish. Java editor automatically open its new class.

In the Java editor, enter the following Java code in the main () method: Display display = new Display (); Shell shell = new Shell (display); shell.setText ("Hello world!"); shell.open (); while (! shell.isDisposed ()) {if (! display.readAndDispatch ()) display.sleep (); } display.dispose (); You will get compilation errors. Right-click in the Java editor and choose Source> Organize Import, then save the changes.

To start the application, right-click your class in the Explorer package and select Run As> Java Application. A new blank window should appear with the inscription "Hello world!". Congratulations! Do you have successfully created the Hello World SWT application!

And here is a screenshot:

screenshot

But when I tried to run the program, instead of displaying a blank screen as expected, it reset it in the terminal:

 Exception in thread "main" java.lang.UnsatisfiedLinkError: Could not load SWT library. Reasons: no swt-cocoa-4233 in java.library.path no swt-cocoa in java.library.path Can't load library: /Users/devenkelling/.swt/lib/macosx/x86_64/libswt-cocoa-4233.jnilib Can't load library: /Users/devenkelling/.swt/lib/macosx/x86_64/libswt-cocoa.jnilib at org.eclipse.swt.internal.Library.loadLibrary(Library.java:331) at org.eclipse.swt.internal.Library.loadLibrary(Library.java:240) at org.eclipse.swt.internal.C.<clinit>(C.java:21) at org.eclipse.swt.widgets.Display.<clinit>(Display.java:101) at HelloWorldSWT.main(HelloWorldSWT.java:11 

I am using an x64 system with installed 64-bit Eclipse and 32-bit and 64-bit versions of Java (I think). Please help. Thanks.

+4
source share
1 answer

Source: Eclipse Forums

This worked for me:

  • Right-click in your HelloWorldSWT project folder;

  • Go to Properties β†’ Left Sidebar of Java Build Path β†’ Tab Projects ;

  • Expand the org.eclipse.swt.cocoa.macosx.x86_64 folder by clicking on the arrow to its left;

  • Select Native library location and click Edit ;

  • Click the Workspace button and select org.eclipse.swt.cocoa.macosx.x86_64 ;

  • Click OK several times;

And you're done! Hope this helps.

+10
source

Source: https://habr.com/ru/post/1440365/


All Articles