平常进行 rap 程序开发一般都是在 win 下面完成 , 然后在 tomcat 下面测试 , 但是程序最终发布一般都是在 linux  aix 上面 , 这个时候就有能会出现一下问题,下面 2 个问题是我们把在开发中真是出现的问题,与大家一起分享下 ;

1、   图片路径

这个是最常用的方法,就是在 rap 中加载图片进行显示,刚开始我们使用的是如下代码

  1. public static String getRoot() {
  2. String path = null ;
  3. try {
  4. path = FileLocator.toFileURL (Platform.getBundle (Activator. PLUGIN_ID ).getEntry( "" )).getPath();
  5. path = path.substring(path.indexOf( "/" ) + 1, path.length());
  6. }
  7. catch (Exception e) {
  8. log .error( "getRoot method :" , e);
  9. }
  10. return path;
  11. }

来获得系统的跟路径 . 但是当程序在移植到 linux 和 aix 上面的时候发现图片路径全部失效 . 可以使用如下方式进行寻址来获得图片。

  1. /**
  2. * 获取图片
  3. * @param fileName
  4. *            图片的名称
  5. * @return 先从缓存对象中查找,若有直接返回,若没有,则将图片加载到缓存中,在从缓存中将图片传给调用着
  6. */
  7. public static Image getImage(String fileName) {
  8. Bundle bundle = Platform.getBundle ( "TelecomUI" );
  9. URL url = bundle.getEntry( "icons" );
  10. try {
  11. url = Platform.asLocalURL (url) ;
  12. }
  13. catch (Exception e) {
  14. }
  15. Image image = registry .get(fileName);
  16. if ( null != image) {
  17. return image;
  18. }
  19. else {
  20. URL fullPathString = bundle.getEntry( "icons/" + fileName);
  21. ImageDescriptor des = ImageDescriptor.createFromURL (fullPathString);
  22. registry .put(fileName, des);
  23. return ImageDescriptor.createFromURL (fullPathString).createImage();
  24. }
  25. }

2、   获得屏幕的分辨率

因为需要把一些弹出的组件居中显示 , 这个时候就需要获得系统的分辨率

刚开始我们使用的方法如下;

  1. screenH = Toolkit.getDefaultToolkit().getScreenSize ().height;
  2. screenW = Toolkit.getDefaultToolkit().getScreenSize ().width;

上面这段代码在 window 下面是没有问题的 , 可是到了 linux 和 aix 下面就报错了 , 找不到

sun.awt.X11.XToolkit 类

可以采用如下方式来获得屏幕的分辨率

DisPlay.getDefault().getClientArea();

3、   其他如果有发现不兼容会陆续补充

04-20 22:52
查看更多