如何在 pom 文件中正确添加本地 JNI jar?
How to add a local JNI jar in a pom file properly?
我有一个提供 REST 的 SpringbootApplication API,我们称它为 fetchPrediction
。
这个 fetchPrediction
API 使用了一些在 JAR 文件中定义的 类,这是一个 JNI。
我的应用程序编译并启动,但是,如果我调用 fetchPrediction
API 它会失败。
当我在 mvn clean install
之后对创建的 jar 执行 jar -xvf 时,我没有看到应该通过包含 jar 依赖项来拾取的 类。
此外,当我尝试 运行 Jar 文件时,我看到 JAR 中的 类 为 ClassNotDefinedException
。
我怎样才能正确地做到这一点?
目前我正在导入JAR依赖如下:
<dependency>
<groupId>jarcom.jarlib</groupId>
<artifactId>jarname</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/jarname.jar</systemPath>
</dependency>
在 spring 引导应用程序中,您通常没有 JNI 部件。此外,spring-boot-maven-plugin 默认情况下不包含与 <scope>system</scope>
的依赖项,这就是为什么您在生成的 jar 中看不到 jar 文件的原因。
您必须配置 spring-boot-maven-plugin 并将 includeSystemScope 设置为 true
作为 described in the docs for the plugin。
<project>
...
<build>
...
<plugins>
...
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.2.4.RELEASE</version>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</execution>
</executions>
...
</plugin>
...
</plugins>
...
</build>
...
</project>
我有一个提供 REST 的 SpringbootApplication API,我们称它为 fetchPrediction
。
这个 fetchPrediction
API 使用了一些在 JAR 文件中定义的 类,这是一个 JNI。
我的应用程序编译并启动,但是,如果我调用 fetchPrediction
API 它会失败。
当我在 mvn clean install
之后对创建的 jar 执行 jar -xvf 时,我没有看到应该通过包含 jar 依赖项来拾取的 类。
此外,当我尝试 运行 Jar 文件时,我看到 JAR 中的 类 为 ClassNotDefinedException
。
我怎样才能正确地做到这一点?
目前我正在导入JAR依赖如下:
<dependency>
<groupId>jarcom.jarlib</groupId>
<artifactId>jarname</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/jarname.jar</systemPath>
</dependency>
在 spring 引导应用程序中,您通常没有 JNI 部件。此外,spring-boot-maven-plugin 默认情况下不包含与 <scope>system</scope>
的依赖项,这就是为什么您在生成的 jar 中看不到 jar 文件的原因。
您必须配置 spring-boot-maven-plugin 并将 includeSystemScope 设置为 true
作为 described in the docs for the plugin。
<project>
...
<build>
...
<plugins>
...
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.2.4.RELEASE</version>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</execution>
</executions>
...
</plugin>
...
</plugins>
...
</build>
...
</project>