代码之家  ›  专栏  ›  技术社区  ›  Raven

构建EclipseRCP应用程序,运行失败

  •  1
  • Raven  · 技术社区  · 14 年前

    成功构建应用程序后,启动失败,因为它依赖于位于META-INF目录中的配置文件,并且在构建后,此目录被压缩到JAR文件中,因此无法访问配置文件。手动解压缩jar、删除jar并用xxx.jar重命名目录后,程序运行没有问题。 SSO登录(Kerberos)需要配置文件。 代码如下:

    Bundle bundle = Platform.getBundle(Application.PLUGIN_ID);
    String path;
    try {
        path = new URL(bundle.getLocation().substring(18)).getPath();
    } catch (MalformedURLException e1) {
        System.out.println(e1);
        path="";
    } 
    System.setProperty("java.security.auth.login.config",path+"META-INF/jaas-win.config");
    

    路径变量包含“plugin/mydomain.pluginame XXXX.jar/” 但系统似乎需要解压罐子。

    我在构建应用程序时出错了吗? 谢谢

    1 回复  |  直到 14 年前
        1
  •  0
  •   Raven    14 年前

    将代码更改为:

        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        URL authconf = null;
        authconf= cl.getResource("META-INF/jaas-win.config");
    
        if (authconf == null) {
            loginContext = null;
            return;
        }
    
        String p;
        try {
             p = URLDecoder.decode(authconf.toExternalForm(), "UTF-8");
             System.setProperty("java.security.auth.login.config", p);
        } catch (UnsupportedEncodingException e1) {
            loginContext = null;
            return;
        }
    

    它现在起作用了。