设为首页 加入收藏

TOP

实例:创建SWT项目的原生库导入问题
2014-11-23 19:57:29 】 浏览:9321
Tags:实例 创建 SWT 目的 原生 导入 问题

  对于 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.


  相关链接:


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Java:Web应用下实现定时任务的简.. 下一篇利用HSQLDB进行Hibernate单元测试

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目