I've got a maven project that includes a JNI lib. It works great in testing within its own project directory. When I run mvn install
the following files are installed to ~/.m2/repository/cam/narzt/getargv/cam_narzt_getargv_Getargv
:
~/.m2/repository/cam/narzt/getargv/cam_narzt_getargv_Getargv
├── 1.0-SNAPSHOT
│ ├── _remote.repositories
│ ├── cam_narzt_getargv_Getargv-1.0-SNAPSHOT-javadoc.jar
│ ├── cam_narzt_getargv_Getargv-1.0-SNAPSHOT-javadoc.jar.asc
│ ├── cam_narzt_getargv_Getargv-1.0-SNAPSHOT.jar
│ ├── cam_narzt_getargv_Getargv-1.0-SNAPSHOT.jar.asc
│ ├── cam_narzt_getargv_Getargv-1.0-SNAPSHOT.pom
│ ├── cam_narzt_getargv_Getargv-1.0-SNAPSHOT.pom.asc
│ └── maven-metadata-local.xml
└── maven-metadata-local.xml
2 directories, 9 files
and the (non-javadoc) jar includes the following files:
0 02-20-2023 21:23 META-INF/
81 02-20-2023 21:23 META-INF/MANIFEST.MF
0 02-20-2023 12:31 cam/
0 02-20-2023 12:31 cam/narzt/
0 02-20-2023 21:23 cam/narzt/getargv/
0 02-20-2023 21:23 META-INF/maven/
0 02-20-2023 21:23 META-INF/maven/cam.narzt.getargv/
0 02-20-2023 21:23 META-INF/maven/cam.narzt.getargv/cam_narzt_getargv_Getargv/
1608 02-20-2023 21:23 cam/narzt/getargv/Main.class
4441 02-20-2023 21:23 cam/narzt/getargv/Getargv.class
9323 02-20-2023 12:08 META-INF/maven/cam.narzt.getargv/cam_narzt_getargv_Getargv/pom.xml
84 02-16-2023 22:48 META-INF/maven/cam.narzt.getargv/cam_narzt_getargv_Getargv/pom.properties
When I add this package to the pom.xml as a dependency in a separate test app, I can depend on the class just fine, but the native lib/methods are missing:
<dependency>
<groupId>cam.narzt.getargv</groupId>
<artifactId>cam_narzt_getargv_Getargv</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
package cam.narzt.testapp;
import java.io.IOException;
import cam.narzt.getargv.Getargv;
public class App {
public static void main(String[] args) {
try {
Getargv.asArray(ProcessHandle.current().pid());
} catch (IOException e) {
// this is just a test, ignore
}
}
}
this gives:
Caused by: java.lang.UnsatisfiedLinkError: 'byte[][] cam.narzt.getargv.Getargv.get_argv_and_argc_of_pid(long)'
at cam.narzt.getargv.Getargv.get_argv_and_argc_of_pid (Native Method)
at cam.narzt.getargv.Getargv.asArray (Getargv.java:52)
at cam.narzt.testapp.App.main (App.java:14)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:279)
at java.lang.Thread.run (Thread.java:1589)
The original project's pom.xml has the instructions for building the jni lib, but the test project doesn't do so, and it doesn't seem to be included into the jar by default. So, what is the preferred way to fix this, and what does that look like in the original project's pom.xml
?