运行我生成的.jar会产生“无法在AMD 64位平台上加载此.dll(机器代码= 0xbd)". [英] Running my generated .jar yields "Can't load this .dll (machine code=0xbd) on a AMD 64-bit platform"
问题描述
我有一个正在使用某些本机库(.dll)的项目.我正在使用Netbeans,并且在运行配置中指定了java.library.path.从Netbeans运行项目不会产生任何错误.
I have a project which is using some native libraries (.dll). I'm using Netbeans, and I've specified java.library.path in the run configuration. Running the project from Netbeans yields no errors.
我正在使用Maven,并且在构建项目时,我的jar是在target
文件夹中构建的.我正在使用Maven资源和依赖插件将所有.dll和程序的依赖项复制到target/lib
.
I'm using Maven, and when building the project my jar is built in the target
folder. I'm copying all the .dlls and my program's dependencies to target/lib
with maven resources and dependency plugins.
当我尝试在Netbeans外部运行应用程序时,出现以下错误:
When I try to run my application "outside" of Netbeans, I get the following error:
Can't load this .dll (machine code=0xbd) on a AMD 64-bit platform
这是我用来运行.jar的命令:
This is the command I use to run the .jar:
java -Djava.library.path=lib\ -jar abcontrol-1.0-SNAPSHOT.jar
这是Netbeans从IDE运行项目的命令(我认为):
This is the command (I think) Netbeans uses to run the project from the IDE:
cd C:\Users\Birger\Workspace\myproject; "JAVA_HOME=C:\\Program Files\\Java\\jdk1.8.0_77" cmd /c "\"\"C:\\Program Files\\NetBeans 8.1\\java\\maven\\bin\\mvn.bat\" -Dexec.args=\"-Djava.library.path=lib\\ -classpath %classpath com.mysite.myproject.Main\" -Dexec.executable=\"C:\\Program Files\\Java\\jdk1.8.0_77\\bin\\java.exe\" -Dmaven.ext.class.path=\"C:\\Program Files\\NetBeans 8.1\\java\\maven-nblib\\netbeans-eventspy.jar\" -Dfile.encoding=UTF-8 org.codehaus.mojo:exec-maven-plugin:1.2.1:exec\""
我当时在想java
命令使用的Java版本与Netbeans不同,所以我尝试了:
I was thinking maybe the java
command uses a different java version than Netbeans, so I tried:
"C:\Program Files\Java\jdk1.8.0_77\bin\java.exe" -Djava.library.path=lib\ -jar abcontrol-1.0-SNAPSHOT.jar
但是,我仍然遇到相同的错误.
But still, I get the same error.
如何在没有Netbeans的情况下运行我的应用程序?
How can I run my application without Netbeans?
编辑
From the answer provided to this question: How can I tell if I'm running in 64-bit JVM or 32-bit JVM (from within a program)?, I added
System.out.println(System.getProperty("sun.arch.data.model"));
以我的代码尝试打印JVM体系结构.我从Netbeans和外部" Netbeans运行该应用程序,在两种情况下,它均打印64
.
To my code to try to get the JVM architecture printed. I ran the application from Netbeans and "outside" netbeans, and in both cases it printed 64
.
EDIT2
运行java -version
打印
java version "1.8.0_77"
Java(TM) SE Runtime Environment (build 1.8.0_77-b03)
Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)
EDIT3
我试图使用相同的依赖项和库来创建另一个项目.这次我没有使用maven,在这个项目中,当我尝试运行该项目时,我得到了相同的错误:
I tried to create another project using the same dependencies and libraries. This time I did NOT use maven, and in this project I get the same errors when I try to run the project:
Can't load this .dll (machine code=0xbd) on a AMD 64-bit platform
很明显,maven正在做一些魔术来使该项目运行.
Clearly, maven is doing some magic to get this project to run.
EDIT4 (越来越失望)
尝试运行这两个命令
"C:\Program Files\Java\jdk1.8.0_91\jre\bin\java.exe" -d32 -Djava.library.path=lib\ -jar abcontrol-1.0-SNAPSHOT.jar
"C:\Program Files\Java\jdk1.8.0_91\bin\java.exe" -d32 -Djava.library.path=lib\ -jar abcontrol-1.0-SNAPSHOT.jar
两种产量
Error: This Java instance does not support a 32-bit JVM. Please install the desired version.
推荐答案
当我尝试运行由Maven构建的JAR(但带有32位DLL-Can't load this .dll (machine code=0xbd) on a IA 32-bit platform
)时,遇到了相同的问题.
奇怪的是:这发生在我将DLL移动到包含其他资源的文件夹中之后,该其他资源在构建期间必须复制.
I experienced the same problem when I tried to run the JAR that was built by Maven (but with a 32 bit DLL - Can't load this .dll (machine code=0xbd) on a IA 32-bit platform
).
Strange thing was: It happened after I moved the DLL in a folder with other resources which have to be copied during the build.
我花了相当长的一段时间才发现,由于某些原因,maven资源插件正在更改DLL文件(可能是bug?).原始DLL文件为76 kb-目标文件夹中复制的DLL为118 kb.在构建过程中文件发生了什么事.
I took me a quite a while to find out that the maven resources plugin was changing the DLL file for some reason (might be a bug?). The original DLL file is 76 kb - the copied DLL in the target folder was 118 kb. Something happened to the file during build.
添加额外的执行以复制DLL文件而无需<filtering>true</filtering>
解决了该问题.
Adding an extra execution to copy the DLL files without <filtering>true</filtering>
solved the problem.
这篇关于运行我生成的.jar会产生“无法在AMD 64位平台上加载此.dll(机器代码= 0xbd)".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!