• 测试技术
  • 博客
  • 视频
  • 开源
  • 论坛
  • 沙龙
  • 下载
  • 杂志
  • 招聘

字号: | 推荐给好友 上一篇 | 下一篇

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

发布: 2007-4-27 13:10 | 作者: seanhe | 来源: | 查看: 35次 | 进入软件测试时代论坛讨论

软件测试时代

  对于 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 文件直接复制到“$Java\jre\bin”目录下,这样才不会引起诸多问题。

  总结解决步骤:

  ①安装 Eclipse 3.1.x 和 SWT Designer,解压 org.eclipse.swt.win32.win32.x86_3.1.x.jar 文件。

  ②复制 swt-win32-xxxx.dll 到“$Java\jre\bin”目录下。

  ③删除解压 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.


  阅读关于 SWT 原生库 导入 问题 的全部文章

文章来源于软件测试时代 http://www.testage.net/


软件测试时代开课信息
Google
关于我们 | 合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2007 TestAge(测试时代) 北京慧灵科技有限公司 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备05002925号
技术支持和业务联系:info@testage.com.cn 电话:010-51297073