com4j在eclipse中工作但不在jar中工作

问题描述 投票:0回答:1

我编写了一个工具(使用spring boot)来获取HP QC v10的详细信息。我正在使用com4j API。程序在eclipse中运行正常,但是当我通过jar运行代码(我使用maven install创建)时抛出异常。

我已经为OTAClient.dll生成了包装器,并制作了包装器qcconn.jar的jar文件。我也注册了dll文件:OTAClient.dll,WebClient.dll和com4j-amd64.dll。我正在使用jdk 8(32位)。

我检查了我的工具的jar文件,它是由maven install生成的,它包含了jar:com4j.jar和qcconn.jar。

当我运行jar文件时抛出异常:java -jar mytool.jar

        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:184) ~[spring-beans-5.1.6.RELEASE.jar!/:5.1.6.RELEASE]
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87) ~[spring-beans-5.1.6.RELEASE.jar!/:5.1.6.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1295) ~[spring-beans-5.1.6.RELEASE.jar!/:5.1.6.RELEASE]
        ... 38 common frames omitted
Caused by: java.lang.ExceptionInInitializerError: null
        at com.qc.ClassFactory.createTDConnection(ClassFactory.java:16) ~[qcconn-1.0.jar!/:na]
        at com.qc.report.gen.app.qc.connection.QCTool.<init>(QCTool.java:23) ~[classes!/:0.0.1-SNAPSHOT]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_201]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[na:1.8.0_201]
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[na:1.8.0_201]
        at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[na:1.8.0_201]
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:172) ~[spring-beans-5.1.6.RELEASE.jar!/:5.1.6.RELEASE]
        ... 40 common frames omitted
Caused by: java.lang.NullPointerException: null
        at com4j.COM4J.loadNativeLibrary(COM4J.java:567) ~[com4j-1.0.jar!/:na]
        at com4j.COM4J.<clinit>(COM4J.java:522) ~[com4j-1.0.jar!/:na]
        ... 47 common frames omitted

Exception in thread "Com4J shutdown hook" java.lang.NoClassDefFoundError: Could not initialize class com4j.COM4J
        at com4j.COM4J$3.run(COM4J.java:476)````
java spring-boot hp-quality-center com4j
1个回答
1
投票

因为我使用32位JVM,每次我都缺少注册com4j-x86.dll。注册后。它开始起作用了。另外请确保在运行jar时,下面的dll文件应该出现在jar存在的同一文件夹下:com4j-x86.dll,OTAClient.dll和WebClient.dll

© www.soinside.com 2019 - 2024. All rights reserved.