java Windows 64 位上的 com4j

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10342765/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 00:38:49  来源:igfitidea点击:

com4j on Windows 64 bit

javacomjava-native-interfacenative-codecom4j

提问by Kong

I've downloaded the latest com4j jars and I'm trying to run through the most simple of their examples.

我已经下载了最新的 com4j jars,我正在尝试运行最简单的示例。

I'm on Windows 7 64 bit and using a 64 bit JVM.

我在 Windows 7 64 位上并使用 64 位 JVM。

When I run the command (from the com4j tutorial):

当我运行命令时(来自 com4j 教程):

java -jar tlbimp.jar -o wsh -p test.wsh %WINDIR%\system32\wshom.ocx

I get:

我得到:

Exception in thread "main" java.lang.UnsatisfiedLinkError: com4j-amd64.dll: %1 is 
not a valid Win32 application
        at java.lang.ClassLoader$NativeLibrary.load(Native Method)
        at java.lang.ClassLoader.loadLibrary0(Unknown Source)
        at java.lang.ClassLoader.loadLibrary(Unknown Source)
        at java.lang.Runtime.load0(Unknown Source)
        at java.lang.System.load(Unknown Source)
        at com4j.COM4J.loadNativeLibrary(COM4J.java:569)
        at com4j.COM4J.<clinit>(COM4J.java:522)
        at com4j.tlbimp.driver.Lib.getLibid(Lib.java:90)
        at com4j.tlbimp.driver.Driver.addLib(Driver.java:38)
        at com4j.tlbimp.driver.Main.doMain(Main.java:123)
        at com4j.tlbimp.driver.Main.main(Main.java:56)
Exception in thread "Com4J shutdown hook" java.lang.NoClassDefFoundError: Could
not initialize class com4j.COM4J
        at com4j.COM4J.run(COM4J.java:476)

The java code extracts "com4j-amd64.dll" next to the jar.

Java 代码提取 jar 旁边的“com4j-amd64.dll”。

采纳答案by Kong

The latest version has just been released:

最新版本刚刚发布:

http://kohsuke.org/2012/04/27/com4j-updates/

http://kohsuke.org/2012/04/27/com4j-updates/

https://github.com/kohsuke/com4j/downloads

https://github.com/kohsuke/com4j/downloads

Using this one solved all my problems.

使用这个解决了我所有的问题。

回答by Nick Rippe

You have two options:

您有两个选择:

  1. Download and use the full latest version (located here: https://github.com/kohsuke/com4j/downloads)
  2. Extract the latest com4j-amd64.dll from the most recent version
    • Download the latest version (located here: https://github.com/kohsuke/com4j/downloads).
    • Open up the com4j.jar with your favorite zip utility (read 7zip)
    • Extract com4j.jar\com4j\com4j-x64.dll to the base directory of your application
    • (optional) Register the dll using REGSVR32 <path to dll>\com4j-x64.dll
  1. 下载并使用完整的最新版本(位于此处:https: //github.com/kohsuke/com4j/downloads
  2. 从最新版本中提取最新的 com4j-amd64.dll
    • 下载最新版本(位于:https: //github.com/kohsuke/com4j/downloads)。
    • 使用您最喜欢的 zip 实用程序打开 com4j.jar(阅读 7zip)
    • 将 com4j.jar\com4j\com4j-x64.dll 解压到应用程序的基目录
    • (可选)使用注册dll REGSVR32 <path to dll>\com4j-x64.dll

回答by carl

I had a similar result at first. I found the com4j-amd64.dll that is produced by com4j is empty. The remedy is to extract the file from the com4j jar file, and put it in the relevant directory by manual action. Com4j will then not auto-produce the file since it is already there. So check if the file is empty as a first step -Carl

我一开始也有类似的结果。我发现com4j生成的com4j-amd64.dll是空的。补救方法是从com4j jar文件中解压出来,手动放到相关目录下。Com4j 将不会自动生成该文件,因为它已经存在。所以第一步检查文件是否为空 -Carl