新闻正文

创建 SWT 项目的原生库导入问题

来源:CSDN  toms  2007-4-1 21:04:55 网友评论 0 条 字体:[ ] ~我要投稿!
《Eclipse 入门和精通》书中讲解了通过 SWT Desinger 自动创建 SWT 项目的步骤,其中导入原生图形库的部分产生了两个问题。分析解决如下——

由 于本书是针对 Eclipse 3.0 编写,版本有一些出入。对于 Eclipse 3.1.x 而言,并没有书中提到的那个“org.eclipse.swt.win32_3.0.1”目录,自然也不会有目录下的 swt.jar 和 swt-win32-3063.dll,这个目录在 Eclipse 3.1.x 中被 org.eclipse.swt.win32.win32.x86_3.1.x.jar 文件替代,而原生库文件也被压缩到这个 jar 文件中,用 WinRAR 解压即可得到。

在 安装了 SWT Designer 后通过其建立项目时,会自动导入所有必须的 jar 文件到项目中,无需手动导入,但如果之前解压了 org.eclipse.swt.win32.win32.x86_3.1.x.jar 文件,请将解压目录删除之后再建立项目,否则会导入出错。这个错误是因为导入了解压得到的 “org.eclipse.swt.win32.win32.x86_3.1.x”目录,可以手动修改为导入整个 jar 文件就 ok 了。


接 下来是原生库的导入,我发现用书上的方法导入原生库到项目中(实际就是将 swt-win32-xxxx.dll 文件复制到项目根目录),会出现问题。后来翻查《SWT/JFace in Action》得知,有多种方法导入原生库,但作者发现最好的方法是将 swt-win32-xxxx.dll 文件直接复制到“$Javajrebin”目录下,这样才不会引起诸多问题。

总结解决步骤:
①安装 Eclipse 3.1.x 和 SWT Designer,解压 org.eclipse.swt.win32.win32.x86_3.1.x.jar 文件。
②复制 swt-win32-xxxx.dll 到“$Javajrebin”目录下。
③删除解压 org.eclipse.swt.win32.win32.x86_3.1.x.jar 得到的文件夹。

④新建 SWT/JFace Java Project,然后就可以直接新建 SWT 类文件了,无需再导入原生包。

PS: 推荐参考《SWT/JFace in Action》配合《Eclipse 入门和精通》进行学习。在《SWT/JFace in Action》附录“Creating projects with SWT/JFace”中的 316 页可以找到关于导入原生图形库的讲述:

Once you’ve found the graphics library, you need to make sure the application launcher can use it. The documentation lists a number of ways to do this, but we’ve found that adding a copy to the $JAVA/jre/bin directory works best.
Other methods, which can be less reliable, include the following:


Option 1: Copy and paste these files directly in the WidgetWindow project.
Option 2: Include the native library in any directory pointed to by the java.library.path variable. This variable, among others, can be seen by clicking Help->About Eclipse Platform->Configuration Details.
Option 3: Go to Control Panel->System->Advanced->Environmental Variables and update the PATH variable with the directory containing the library file.

收藏到ViVi   收藏此页到365Key
上一篇:程序员分成几种不同的境界
下一篇:MyEclipse 5.0 + WebLogic 9.2 配置详解
用户名:新注册) 密码: 匿名评论 [所有评论]
评论内容:不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
本栏搜索
  • Google
   网站首页 -  网站地图 -  技术学习 -  网站投稿 -  帮助中心
Copyright 2003-2008 www.javah.net All Rights Reserved
2008 如果你喜欢本站 请收藏本站 并推荐给你的朋友一起分享