我目前正在重写我的操作系统项目netlib-java,以便尽可能方便地被devs和最终用户使用。
但是,作为maven本机设置的一部分,对于我想创建的每个本机二进制文件,我似乎需要一个单独的pom.xml。大多数这些文件实际上在不同的平台上是相同的。
如何减少本地构建文件的样板?,例如:
(除了输出文件的名称、编译器标志和javah的目标平台外,几乎所有东西都是在OS目标之间共享的)。
还有一些较小但相关的问题:
jnilib (etc)部署,而使用默认的classifier来部署jar (我可以创建native分类器jar,但是对于最终用户来说这是很尴尬的)。发布于 2013-08-08 14:15:50
maven的继承特性可以大大减少样板代码。为了保持简单,我省略了javah和其他JNI-东西,只创建了两个C-项目和一个常见的父项目。目录-结构如下所示:
+-NativeParent
! !
! +-src/main/native
! +-pom.xml
+-NativeTest1
! !
! +-pom.xml
+-NativeTest2
!
+-pom.xmlNativeParent包含所有源代码,pom.xml包含几乎所有定义:
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>nativeParent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>parent-pom</name>
<modules>
<module>../NativeTest1</module>
<module>../NativeTest2</module>
</modules>
<dependencies>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>native-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<sources>
<source>
<directory>../NativeParent/src/main/native</directory>
<fileNames>
<fileName>krbwinclient.c</fileName>
</fileNames>
</source>
</sources>
<linkerStartOptions>
<linkerStartOption>-Wl,--kill-at</linkerStartOption>
<linkerStartOption>-shared</linkerStartOption>
</linkerStartOptions>
<linkerEndOptions>
<linkerEndOption>-lSecur32</linkerEndOption>
<linkerEndOption>-lOle32</linkerEndOption>
</linkerEndOptions>
</configuration>
</plugin>
</plugins>
</build>
</project>NativeTest2 1和NativeTest2 2的poms可以非常精简,因为它们只需要定义与父-pom不同的属性。
NativeTest1:
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>test</groupId>
<artifactId>nativeParent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>test</groupId>
<artifactId>native1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>so</packaging>
<build>
<finalName>native1.so</finalName>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>native-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<compilerStartOptions>
<compilerStartOption>-Wl,--add-stdcall-alias</compilerStartOption>
<compilerStartOption>-DBUILD_SO</compilerStartOption>
</compilerStartOptions>
</configuration>
</plugin>
</plugins>
</build>
</project>和NativeTest2:
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>test</groupId>
<artifactId>nativeParent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>test</groupId>
<artifactId>native2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>dll</packaging>
<build>
<finalName>native1.so</finalName>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>native-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<compilerStartOptions>
<compilerStartOption>-Wl,--add-stdcall-alias</compilerStartOption>
<compilerStartOption>-DBUILD_DLL</compilerStartOption>
</compilerStartOptions>
</configuration>
</plugin>
</plugins>
</build>
</project>唯一不同的地方是包类型、目标名称和编译选项,但大多数配置都是从父-pom获取的。
请注意,只有一个编译器- so属性,所以您可以在子-pom中使用几个同名属性,您将丢失父-pom中所有同名条目。
我希望这是你一直在寻找的东西-它仍然是一些样板代码,但它是大大减少了。
https://stackoverflow.com/questions/17912077
复制相似问题