Running my generated .jar yields “Can't load this .dll (machine code=0xbd) on a AMD 64-bit platform”

百般思念 提交于 2019-12-24 08:12:37

问题


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.

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.

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

This is the command I use to run the .jar:

java -Djava.library.path=lib\ -jar abcontrol-1.0-SNAPSHOT.jar

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\""

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.

How can I run my application without Netbeans?

EDIT

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"));

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

Running java -version prints

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

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

Clearly, maven is doing some magic to get this project to run.

EDIT4 (getting deseprate)

Tried running these two commands

"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

Both yields

Error: This Java instance does not support a 32-bit JVM. Please install the desired version.

回答1:


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.

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.

Adding an extra execution to copy the DLL files without <filtering>true</filtering> solved the problem.




回答2:


Another alternative solution is to use what was suggested in the following post: https://stackoverflow.com/a/24282250/9293631 Which basically is to add a project level configuration so maven ignores the binary extension while filtering resources:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>3.0.2</version>
    <configuration>
      ...
      <nonFilteredFileExtensions>
        <nonFilteredFileExtension>pdf</nonFilteredFileExtension>
        <nonFilteredFileExtension>swf</nonFilteredFileExtension>
      </nonFilteredFileExtensions>
      ...
    </configuration>
  </plugin>


来源:https://stackoverflow.com/questions/38244970/running-my-generated-jar-yields-cant-load-this-dll-machine-code-0xbd-on-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!