gpt4 book ai didi

java - WinRun4J - 无法加载库 jar

转载 作者:太空宇宙 更新时间:2023-11-04 07:49:09 25 4
gpt4 key购买 nike

我正在尝试使用 WinRun4J 将 Java 程序作为 Windows 服务执行。该服务已正确创建并运行,直到由于 ClassNotFoundException 而停止:

org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from relative location [appContext-webServices.xml]
Offending resource: class path resource [spring/appContext.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [spring/appContext-webServices.xml]; nested exception is java.lang.RuntimeException: javax.xml.bind.JAXBException
- with linked exception:
[java.lang.ClassNotFoundException: com/sun/xml/bind/v2/ContextFactory]
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:76)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:271)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseDefaultElement(DefaultBeanDefinitionDocumentReader.java:196)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:181)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:140)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:111)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:522)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:436)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at br.com.gep.sped.extrator.AppServico.serviceMain(AppServico.java:22)
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [spring/appContext-webServices.xml]; nested exception is java.lang.RuntimeException: javax.xml.bind.JAXBException
- with linked exception:
[java.lang.ClassNotFoundException: com/sun/xml/bind/v2/ContextFactory]
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:412)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:255)
... 20 common frames omitted
Caused by: java.lang.RuntimeException: javax.xml.bind.JAXBException
- with linked exception:
[java.lang.ClassNotFoundException: com/sun/xml/bind/v2/ContextFactory]
at org.apache.cxf.configuration.spring.AbstractBeanDefinitionParser.getContext(AbstractBeanDefinitionParser.java:326)
at org.apache.cxf.configuration.spring.AbstractBeanDefinitionParser.mapElementToJaxbProperty(AbstractBeanDefinitionParser.java:352)
at org.apache.cxf.configuration.spring.AbstractBeanDefinitionParser.mapElementToJaxbProperty(AbstractBeanDefinitionParser.java:294)
at org.apache.cxf.transport.http.spring.HttpConduitBeanDefinitionParser.doParse(HttpConduitBeanDefinitionParser.java:58)
at org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser.parseInternal(AbstractSingleBeanDefinitionParser.java:85)
at org.springframework.beans.factory.xml.AbstractBeanDefinitionParser.parse(AbstractBeanDefinitionParser.java:59)
at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:73)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1419)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1409)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:184)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:140)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:111)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
... 23 common frames omitted
Caused by: javax.xml.bind.JAXBException: null
at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
at javax.xml.bind.ContextFinder.find(Unknown Source)
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
at org.apache.cxf.common.jaxb.JAXBContextCache$2.run(JAXBContextCache.java:267)
at org.apache.cxf.common.jaxb.JAXBContextCache$2.run(JAXBContextCache.java:265)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.cxf.common.jaxb.JAXBContextCache.createContext(JAXBContextCache.java:265)
at org.apache.cxf.common.jaxb.JAXBContextCache.getCachedContextAndSchemas(JAXBContextCache.java:172)
at org.apache.cxf.configuration.spring.AbstractBeanDefinitionParser.getContext(AbstractBeanDefinitionParser.java:321)
... 36 common frames omitted
Caused by: java.lang.ClassNotFoundException: com/sun/xml/bind/v2/ContextFactory
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at javax.xml.bind.ContextFinder.safeLoadClass(Unknown Source)
... 45 common frames omitted

我怀疑 WinRun4J 没有加载 lib 文件夹中的 lib jar。我的应用程序工作目录是这样的:

application directory
-> bin directory
-> lib directory

主要应用程序 jar 位于 bin 文件夹中,其他 jar 位于 lib 文件夹中。这是我的 servico.ini 文件,由 WinRun4J 使用:

vm.version.min=1.6
single.instance=process
service.class=br.com.gep.sped.extrator.AppServico
service.id=AgenteWIN
service.name=Agente Win
service.description=Agente de extração dos dados SPED.
classpath.1=*.jar
classpath.2=../lib/*.jar
vmarg.1=-Xmn100M
vmarg.2=-Xms500M
vmarg.3=-Xmx500M

我在 classpath.2 中尝试了很多变体,但没有成功。
我做错了什么?

最佳答案

作为 Windows,您可能需要使用反斜杠而不是正斜杠

classpath.2=..\lib\*.jar

如果这还不够,请尝试添加

working.directory=.

确保根据正确的基目录解析相对路径。如果所有其他方法都失败,您可以使用 Class-Path 将 list 添加到主 JAR 文件中,该 Class-Path 枚举所有 ../lib/file.jar 文件,并完全删除 classpath.2

编辑:看到堆栈跟踪,WinRun4J 似乎没有正确设置线程上下文类加载器。尝试添加

Thread.currentThread().setContextClassLoader(
AppServico.class.getClassLoader());

在实例化任何 Spring/CXF 相关内容之前,到 serviceMain 的顶部。

关于java - WinRun4J - 无法加载库 jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14780911/

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