gpt4 book ai didi

java - Install4j:Windows 安装程序显示 java.lang.LinkageError:ClassCastException

转载 作者:行者123 更新时间:2023-11-30 08:37:57 27 4
gpt4 key购买 nike

我正在为 Windows 和 Linux 系统生成安装程序。在欢迎屏幕之后,我有一个 CustomForm 组件,我在其中获取用户详细信息,然后使用 javax.ws.rs.client.ClientBuilder 将它们发送到服务器。但在 Windows 中,当我的类尝试从 ClientBuilder 构建客户端时,安装程​​序会抛出 java.lang.LinkageError: ClassCastException。整个日志如下:

    java.lang.LinkageError: ClassCastException: attempting to cast
jar:file:/C:/Users/lutful.kabir/AppData/Local/Temp/e4j363A.tmp_dir1460795758/user/javaee-api-7.0.jar!/javax/ws/rs/client/ClientBuilder.class to
jar:file:/C:/Users/lutful.kabir/AppData/Local/Temp/e4j363A.tmp_dir1460795758/user/javaee-api-7.0.jar!/javax/ws/rs/client/ClientBuilder.class
at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:97)
at javax.ws.rs.client.ClientBuilder.newClient(ClientBuilder.java:114)
at install4j.AuthorizationHandler.verifyAuthorization(AuthorizationHandler.java:21)
at install4j.backendsetup.VerifyBackend.install(VerifyBackend.java:27)
at com.install4j.runtime.installer.InstallerContextImpl$2.fetchValue(InstallerContextImpl.java:167)
at com.install4j.runtime.installer.InstallerContextImpl$2.fetchValue(InstallerContextImpl.java:164)
at com.install4j.runtime.installer.helper.comm.actions.FetchObjectAction.execute(FetchObjectAction.java:14)
at com.install4j.runtime.installer.helper.comm.HelperCommunication.executeActionDirect(HelperCommunication.java:272)
at com.install4j.runtime.installer.helper.comm.HelperCommunication.executeActionInt(HelperCommunication.java:247)
at com.install4j.runtime.installer.helper.comm.HelperCommunication.executeActionChecked(HelperCommunication.java:185)
at com.install4j.runtime.installer.helper.comm.HelperCommunication.fetchObjectChecked(HelperCommunication.java:168)
at com.install4j.runtime.installer.InstallerContextImpl.performActionIntStatic(InstallerContextImpl.java:164)
at com.install4j.runtime.installer.InstallerContextImpl.performActionInt(InstallerContextImpl.java:152)
at com.install4j.runtime.installer.ContextImpl.performAction(ContextImpl.java:1099)
at com.install4j.runtime.installer.controller.Controller.executeAction(Controller.java:367)
at com.install4j.runtime.installer.controller.Controller.executeActions(Controller.java:333)
at com.install4j.runtime.installer.controller.Controller.handleCommand(Controller.java:194)
at com.install4j.runtime.installer.controller.Controller.start(Controller.java:94)
at com.install4j.runtime.installer.Installer.runInProcess(Installer.java:59)
at com.install4j.runtime.installer.Installer.main(Installer.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.exe4j.runtime.LauncherEngine.launch(LauncherEngine.java:62)
at com.exe4j.runtime.WinLauncher.main(WinLauncher.java:101)
at com.install4j.runtime.launcher.WinLauncher.main(WinLauncher.java:26)

AuthorizationHandler 的代码如下:

package install4j;

import java.net.ConnectException;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import com.install4j.api.Util;
import com.install4j.api.context.InstallerContext;

import installerconfigparams.utils.InstallerParameter;

public class AuthorizationHandler {

public static boolean verifyAuthorization(String authToken, InstallerContext context) throws ConnectException {
Client client = ClientBuilder.newClient();
WebTarget target = client.target(InstallerParameter.CENTRAL_SERVER_URL.getStringValue())
.path(InstallerParameter.PATH_BACKEND_VERIFICATION.getStringValue());
Builder builder = target.request(MediaType.APPLICATION_JSON);
builder.header(InstallerParameter.AUTHORIZATION_HEADER.getStringValue(), authToken);
Invocation invocation = builder.buildGet();
Response response;
response = invocation.invoke();
response.getStringHeaders();
int status = response.getStatus();
if (InstallerParameter.HTTP_200.getIntValue() != status) {
String args = response.getHeaderString("error");
Util.showErrorMessage(context.getMessage("installer.backend.login.invalid") + args);
return false;
}
Util.showMessage(context.getMessage("installer.backend.login.successful"));
return true;
}

现在,据我所知并根据我的互联网研究,当可能存在重复资源时会发生这种情况(从日志中您还可以看到它正在使用的 ClientBuilder 类也来自相同的路径)。我已确保没有添加重复的 jar,以便安装程序可以混淆它。我不太熟悉 ClassLoaders 或它在 Install4j 中的工作方式。我也尝试过使用 Run Script 操作,直接在此处编写代码,但最终遇到了同样的异常。

自从构建安装程序以来,我一直在使用相同的类和方法。直到今天都没有任何问题。在我遇到这个问题之前,我什至检查了我的旧提交。但结果是一样的。并且这个问题只发生在 Windows 中的安装程序。

最佳答案

JAX-WS 对某些操作使用上下文类加载器。呼唤

 Thread.currentThread().setContextClassLoader(getClass().getClassLoader());

将上下文类加载器设置为与加载脚本相同的类加载器,这与自 install4j 6.1 以来的系统类加载器不同。

从 install4j 6.1.2 开始,上下文类加载器将自动调整,因此不再需要上述解决方法。

关于java - Install4j:Windows 安装程序显示 java.lang.LinkageError:ClassCastException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36845199/

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