1

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.
Community
  • 1
  • 1
birgersp
  • 3,909
  • 8
  • 39
  • 79
  • 2
    Are you using a 32-bit or a 64-bit JVM? The bitness of your JVM and native library must match. A 32-bit JVM cannot load a 64-bit DLL and vice versa. – Jesper Jul 07 '16 at 12:04
  • I am 99% sure that I'm using 64-bit JVM. But how can I verify this? Also, I guess Netbeans uses the same JVM? If that's the case, how can Netbeans make it work while I can't? – birgersp Jul 07 '16 at 12:07
  • Send dll location as parameter or check with the new File("myDllLocation").exist(); to validate before than you load system library – HRgiger Jul 07 '16 at 12:11
  • Oh my bad please ignore it can see the file – HRgiger Jul 07 '16 at 12:11
  • Running `java -version` on the command line should say something like "Java HotSpot(TM) 64-Bit Server VM" if it's a 64-bit JVM. – Jesper Jul 07 '16 at 12:20
  • I had an update installed, I removed it just to be sure but I still get the same error. Added `java -version` output to my question – birgersp Jul 07 '16 at 12:29
  • @Jesper My third edit should be quite relevant, Maven in Netbeans is doing something to specify the right architecture – birgersp Jul 07 '16 at 12:45

2 Answers2

3

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.

ingo
  • 116
  • 1
  • 9
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>
sauloos
  • 21
  • 1