org.eclipse.swt.*;导入org.eclipse无法解决

2022-01-16 00:00:00 import eclipse-plugin eclipse

我正在尝试编写一个需要导入语句import org.eclipse.swt.*; 的小程序.(我正在练习 THIS 教程).

但是,Eclipse 不会编译该程序并给我错误无法解析导入 org.eclipse"

Google 这次在寻找答案方面可不是那么好.

解决方案

这是因为您尚未将 SWT 库添加到构建路径中.按照教程的步骤操作:

<块引用>

  1. 下载 SWT 库.对于 3.1.2 版本的 eclipse,SWT 库位于http://archive.eclipse.org/eclipse/downloads/drops/R-3.1.2-200601181600/index.php查找标题为 SWT 二进制和源代码的部分.
  2. 从主菜单工具栏中,选择文件",然后选择导入".这样做会弹出导入向导"对话框.
  3. 现在选择Existing Projects into Workspace"并点击Next"按钮.
  4. 点击选择存档文件",然后点击浏览"按钮.现在找到您在第 1 步中下载的 SWT 存档.
  5. 单击完成"按钮完成将 SWT 项目导入您的工作区.
  6. 从文件 > 新建 Java 项目创建新的 Java 项目.
  7. 右键单击项目并选择属性"命令以打开属性"对话框.
  8. 选择 Java 构建路径,然后选择项目"选项卡,然后单击添加"按钮.
  9. 选择 org.eclipse.swt 项目并单击确定"完成将 SWT 库添加到项目的类路径中

I am trying to write a small program that requires the import statement import org.eclipse.swt.*;. (I'm practicing with THIS tutorial).

However, Eclipse won't compile the program and is giving me the error "The import org.eclipse cannot be resolved"

Google hasn't been such a a great friend at finding the answer this time.

解决方案

This is because you haven't added the SWT library to your buildpath. Follow the steps of the tutorial:

  1. Download SWT library. For 3.1.2 version of eclipse, SWT library is available at http://archive.eclipse.org/eclipse/downloads/drops/R-3.1.2-200601181600/index.php Look for the section titled SWT Binary and Source.
  2. From main menu tool bar, select "File" followed by "Import". Doing so will bring up the "Import wizard" dialog.
  3. Now select "Existing Projects into Workspace" and click on "Next" button.
  4. Click on "Select archive file" followed by "Browse" button. Now locate the SWT archive that you downloaded in step 1.
  5. Click the Finish button to finish importing the SWT project into your workspace.
  6. Create new java project from File > New Java Project.
  7. Right-click on the project and select the Properties command to open the Properties dialog.
  8. Select the Java Build Path followed by Projects tab and click the Add button.
  9. Select the org.eclipse.swt project and click OK to finish adding the SWT libraries to your project's classpath

相关文章