gpt4 book ai didi

java - 构建Eclipse RCP应用程序,运行失败

转载 作者:行者123 更新时间:2023-12-01 05:57:22 24 4
gpt4 key购买 nike

成功构建我的应用程序后,启动失败,因为它依赖于位于 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/”的内容但系统似乎需要解压 jar。

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

最佳答案

将代码更改为:

    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;
}

现在可以使用了。

关于java - 构建Eclipse RCP应用程序,运行失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2468264/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com