Practice Eclipse: Set SWT/jface Environment Variables

Source: Internet
Author: User

SWT and jface are two emerging Java GUI Libraries. Combined with the use of the eclipse development platform, we can quickly develop applications with beautiful and efficient user interfaces. However, before that, we must first set appropriate environment variables for SWT/jface to compile and execute code smoothly.

 

 

I,Start

 

If the appropriate SWT/jface environment variables are not set for our project, eclipse reports an error during compilation because the required library file cannot be found, as shown in:

 

We can see a lot of code below the red wave line, and the corresponding lines are also accompanied by a red light bulb, orange box and other icons, indicating that the Code has encountered problems during compilation, if display cannot be parsed, this is because the required library file is not found during compilation.

 

2. SWTCreate a class PATH variable

 

Suppose the name of our development project is mywindow. In eclipse, right-click the project and choose "properties" from the drop-down menu. Then, select "Java build path" on the left side of the screen to tell the Java compiler where to find the desired SWT/jface file.

Click the "library" tab, and then click the "add variable" button to add various variables. They are used to represent the libraries (*. Jar) required for compilation ). In the create variable classiclink entry dialog box, click Configure variable. When the "Preferences" window appears, click "new. Enter swt_lib in the "name" box, and then click "file" to find the corresponding library file. In the displayed dialog box, find $ Eclipse/plugins/org. eclipse. SWT. win32_x.y.z/WS/Win32/SWT. jar ($ eclipse here refers to the eclipse installation directory, which is the same as this in the following), and double-click the file.

As shown in:

In the "Create variable entry" dialog box, click the "OK" button. Then, the swt_lib variable enters the class PATH variable table.

 

3. For jfaceCreate a class PATH variable

 

1. Use the method described above to create a variable named jface_lib for the jface. Jar (or jface_new.jar) file. This file is located in

$ Eclipse/plugins/org. Eclipse. jface_x.y.z /.

2. Create a variable named boot_lib for the runtime. jar file located in $ Eclipse/plugins/org. Eclipse. Core. boot_x.y.z.

3. Create a variable named runtime_lib for the runtime. jar file located in $ Eclipse/plugins/org. Eclipse. Core. runtime_x.y.z.

4. Same as above, create a variable named workbench_lib for the workbench. Jar (or workbench_new.jar) file located in $ Eclipse/plugins/org. Eclipse. UI. workbench_x.y.z.

5. Click "OK" in the "Preferences" window.

 

4. Add the Library Class PATH variable to the Development Project

 

1. In the workbench, right-click the mywindow project and select the "properties" option.

2. Select "Java build path" in the left pane and click the "library" tab in the right pane.

3. Click the "add variable" button. In the "Create variable class path entry" box, select the variables jface_lib, boot_lib, runtime_lib, and workbench_lib.

Click OK.

4. Create a variable named jface_lib in the $ Eclipse/plugin/org. Eclipse. jface_x.y.z/jface. Jar (or jface_new.jar) file.

5. Create a variable named boot_lib in the $ Eclipse/plugins/org. Eclipse. Core. boot_x.y.z/runtime. jar file.

6. Create a variable named runtime_lib in the $ Eclipse/plugins/org. Eclipse. Core. runtime_x.y.z/runtime. jar file.

7. Create a variable in the $ Eclipse/plugins/org. Eclipse. UI. workbench_x.y.z/workbench. Jar (or workbench_new.jar) file named workbench_lib.

8. Finally, click "OK" in the "properties" window.

 

5. Add a local graphics library for the project

 

We know that the GUI compiled with SWT/jface has the same appearance and speed as that of the running platform. At this time, because SWT/jface calls the graphics library that comes with the operating system, therefore, we need to find the local graphics library for our program.

 

1. the SWT local graphics file is generally named swt-win-nnnn.dll, where NNNN represents four integers located at $ Eclipse/plugins/org. eclipse. SWT. win32_x.y.z/OS/Win32/x86.swt directory.

2. to ensure that these library files can be used by our program, the safest way is to copy them to the $ Java/JRE/bin directory (here $ Java refers to the Java installation directory ). In addition, you can copy them to your development project. Alternatively, you can add the local graphics library to any directory contained in the Java. Library. PATH variable. Click "help"> "about eclipse platform"> "configuration details" to view the change volume. In addition, you can also modify the PATH variable through "Control Panel"> "system"> "advanced"> "environment variable" to include directories containing library files.

 

Vi. Running results

 

To view the running results of our code, click helloswt in package Resource Manager. java program, select the "running mode" menu item from the "run" menu, and finally select "Java application ". Shows the execution result of our program:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.