我有一个默认的jersey项目,从https://start.spring.io/下载,我添加了一个lib文件夹,并在其中添加了一个用C ++编译的库,可通过JNI进行调用。在Eclipse中,将“ lib”目录添加到类路径中,并且可以通过“ Java Application”选项完美运行。尝试使用maven命令mvn spring-boot:run
直接运行时,尝试加载库时出现错误。我的pom文件是:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>ec.com.extractdatacom</groupId>
<artifactId>RestExtractDataDicom</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>RestExtractDataDicom</name>
<description>Proyecto para procesar archivos dicom</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.opencsv/opencsv -->
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>5.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.swt</groupId>
<artifactId>org.eclipse.swt.gtk.linux.x86_64</artifactId>
<version>4.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>${project.basedir}/lib</additionalClasspathElement>
</additionalClasspathElements>
<systemPropertyVariables>
<propertyName>java.library.path</propertyName>
<buildDirectory>${project.basedir}/lib</buildDirectory>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>
仅在mvn spring-boot:run
为以下情况时出错:
java.lang.UnsatisfiedLinkError: no ExtractDataDicom in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867) ~[na:1.8.0_121]
at java.lang.Runtime.loadLibrary0(Runtime.java:870) ~[na:1.8.0_121]
at java.lang.System.loadLibrary(System.java:1122) ~[na:1.8.0_121]
at ec.com.extractdatacom.jni.ExtractDataDicom.<clinit>(ExtractDataDicom.java:12) ~[classes/:na]