gpt4 book ai didi

Java JNI Maven native-maven-plugin - 如何设置共享库的最终名称

转载 作者:行者123 更新时间:2023-12-01 14:18:47 24 4
gpt4 key购买 nike

我正在尝试使用 JNI 和 Maven 来了解如何使构建过程自动化。当涉及到输出文件名时,我在 Linux 平台上遇到了一些困难。当我运行maven构建时(下面是linux平台的pom.xml),返回的共享库文件名是jniExampleNative.so。如果我尝试用它运行 java 程序,我会得到 java.lang.UnsatisfiedLinkError: no jniExampleNative in java.library.path。如果我将文件重命名为 libjniExampleNative.so 它会起作用。

我想设置 Maven,使其自动创建具有工作文件名的文件,但不知道如何操作。我尝试设置 linkerFinalName 选项(在下面的 pom.xml 中有注释),但我得到 The packaging for this project did not assign a file to the build artifact.

我哪里做错了,如何设置输出共享库的名称?

<project>
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>net.tricoder.jnitest</groupId>
<artifactId>nativeParent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<groupId>net.tricoder.jnitest</groupId>
<artifactId>jniExampleNative</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>JNI example native Linux</name>
<url>http://maven.apache.org</url>

<packaging>so</packaging>

<dependencies>
<dependency>
<groupId>net.tricoder.jnitest</groupId>
<artifactId>jniExampleJava</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>native-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<!-- trigger javah -->
<javahOS>linux</javahOS>

<compilerProvider>generic-classic</compilerProvider>
<compilerExecutable>gcc</compilerExecutable>

<linkerExecutable>gcc</linkerExecutable>
<sources>
<source>
<directory>../src/main/native</directory>
<fileNames>
<fileName>jni_example.c</fileName>
</fileNames>
</source>
</sources>

<compilerStartOptions>
<compilerStartOption>-fPIC</compilerStartOption>
</compilerStartOptions>

<linkerStartOptions>
<linkerStartOption>-shared</linkerStartOption>
</linkerStartOptions>

<!--linkerOutputDirectory>${project.build.directory}</linkerOutputDirectory>
<linkerFinalName>libjniExampleNative</linkerFinalName-->

</configuration>

<executions>
<execution>
<id>javah</id>
<phase>generate-sources</phase>
<configuration>
<javahOS>linux</javahOS>
<javahProvider>default</javahProvider>
<javahOutputDirectory>${project.build.directory}/custom-javah</javahOutputDirectory>
<workingDirectory>${basedir}</workingDirectory>
<javahOutputFileName>NativeStuff.h</javahOutputFileName>
<javahClassNames>
<javahClassName>net.tricoder.jnitest.NativeStuff</javahClassName>
</javahClassNames>
</configuration>
<goals>
<goal>javah</goal>
</goals>
</execution>
</executions>

</plugin>
</plugins>
</build>
</project>

最佳答案

<linkerFinalName>libjniExampleNative</linkerFinalName>做的伎俩。问题出在我运行的生命周期上 mvn clean install -P linux . install相退The packaging for this project did not assign a file to the build artifact .

改成mvn clean package -P linux后它工作正常。现在我必须弄清楚为什么 install<linkerFinalName>libjniExampleNative</linkerFinalName> 冲突,因为只有在设置 linkerFinalName 时才会出现错误选项。

关于Java JNI Maven native-maven-plugin - 如何设置共享库的最终名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25138413/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com