I've seen several approaches to this problem, and the most popular one is to install the libraries to my local maven repository. However, I can't wrap my head around solving my particular case. I think the problem is that my dependency cant find the .dll's it needs to run.
These are the files:
jni4net.j-0.8.8.0.jar
jni4net.n.w32.v20-0.8.8.0.dll
jni4net.n.w32.v40-0.8.8.0.dll
jni4net.n.w64.v20-0.8.8.0.dll
jni4net.n.w64.v40-0.8.8.0.dll
jni4net.n-0.8.8.0.dll
I've tried doing this in a non-Maven (NetBeans) project. There, I added the .jar
under Project Properties → Libraries and I set the working directory to the location of the .dll
s. This is working.
However, I need to implement the libraries to a Maven project. I installed the .jar
file to my local Maven repository. But when I run the application, it complains that it can't find the .dll
s. I tried to specify java.library.path
but no dice. Can someone help me with this one?
EDIT
I tried putting all the files into a lib
folder in my project. I added the following to my pom.xml
:
<dependency>
<groupId>sample</groupId>
<artifactId>com.sample</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/jni4net.j-0.8.8.0.jar</systemPath>
</dependency>
This yields the following exception when I run the application (I obscured the actual package names for the sake of this example):
Exception in thread "main" java.lang.NoClassDefFoundError: net/sf/jni4net/Bridge
at myhost.Main.main(Main.java:37)
Caused by: java.lang.ClassNotFoundException: net.sf.jni4net.Bridge
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
EDIT2
I tried installing the jar and all the .dlls to a project-specific repository with the following bash script:
call mvn install:install-file -DlocalRepositoryPath=%librepodir% -DcreateChecksum=true -Dpackaging=jar -Dfile=proxygen/jni4net.j-0.8.8.0.jar -DgroupId=jni4net -DartifactId=jni4net.j -Dversion=0.8.8.0
call mvn install:install-file -DlocalRepositoryPath=%librepodir% -DcreateChecksum=true -Dpackaging=dll -Dfile=proxygen/jni4net.n.w32.v20-0.8.8.0.dll -DgroupId=jni4net -DartifactId=jni4net.n.w32.v20 -Dversion=0.8.8.0
call mvn install:install-file -DlocalRepositoryPath=%librepodir% -DcreateChecksum=true -Dpackaging=dll -Dfile=proxygen/jni4net.n.w32.v40-0.8.8.0.dll -DgroupId=jni4net -DartifactId=jni4net.n.w32.v40 -Dversion=0.8.8.0
call mvn install:install-file -DlocalRepositoryPath=%librepodir% -DcreateChecksum=true -Dpackaging=dll -Dfile=proxygen/jni4net.n.w64.v20-0.8.8.0.dll -DgroupId=jni4net -DartifactId=jni4net.n.w64.v20 -Dversion=0.8.8.0
call mvn install:install-file -DlocalRepositoryPath=%librepodir% -DcreateChecksum=true -Dpackaging=dll -Dfile=proxygen/jni4net.n.w64.v40-0.8.8.0.dll -DgroupId=jni4net -DartifactId=jni4net.n.w64.v40 -Dversion=0.8.8.0
Then, I added the following to my project's pom.xml:
<project>
<repositories>
<repository>
<id>repo</id>
<url>file://${project.basedir}/repo</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>jni4net</groupId>
<artifactId>jni4net.j</artifactId>
<version>0.8.8.0</version>
</dependency>
<dependency>
<groupId>jni4net</groupId>
<artifactId>jni4net.n.w32.v20</artifactId>
<version>0.8.8.0</version>
<scope>runtime</scope>
<type>dll</type>
</dependency>
<dependency>
<groupId>jni4net</groupId>
<artifactId>jni4net.n.w32.v40</artifactId>
<version>0.8.8.0</version>
<scope>runtime</scope>
<type>dll</type>
</dependency>
<dependency>
<groupId>jni4net</groupId>
<artifactId>jni4net.n.w64.v20</artifactId>
<version>0.8.8.0</version>
<scope>runtime</scope>
<type>dll</type>
</dependency>
<dependency>
<groupId>jni4net</groupId>
<artifactId>jni4net.n.w64.v40</artifactId>
<version>0.8.8.0</version>
<scope>runtime</scope>
<type>dll</type>
</dependency>
</dependencies>
</project>
Building the project works fine, but running it yields the following exception:
Can't init BridgeExport:The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
Can't init BridgeExport:System.IO.FileNotFoundException: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
at System.Reflection.RuntimeAssembly.nLoadFile(String path, Evidence evidence)
at System.Reflection.Assembly.LoadFile(String path)
at net.sf.jni4net.BridgeExport.initDotNet(IntPtr envi, IntPtr clazz)
Can't initialize jni4net Bridge from C:\Users\Birger\.m2\repository\jni4net\jni4net.n.w64.v40\0.8.8.0\jni4net.n.w64.v40-0.8.8.0.dll
Can't initialize jni4net BridgeCan't initialize jni4net Bridge. Code:-100
Exception in thread "main" net.sf.jni4net.inj.INJException: Can't initialize jni4net Bridge
at net.sf.jni4net.CLRLoader.init(CLRLoader.java:45)
at net.sf.jni4net.Bridge.init(Bridge.java:35)
at net.sf.jni4net.Bridge.init(Bridge.java:31)
at no.offsim.ntnu.abcontrol.Main.main(Main.java:37)
Caused by: net.sf.jni4net.inj.INJException: Can't initialize jni4net Bridge. Code:-100
at net.sf.jni4net.CLRLoader.init(CLRLoader.java:40)
... 3 more