maven의 상속 기능을 사용하면 상용구 코드를 상당히 줄일 수 있습니다. javah 및 기타 JNI 관련 내용을 생략하고 두 개의 C 프로젝트와 공통 상위 프로젝트를 작성했습니다. 디렉토리 구조는 다음과 같이이다 :
+-NativeParent
! !
! +-src/main/native
! +-pom.xml
+-NativeTest1
! !
! +-pom.xml
+-NativeTest2
!
+-pom.xml
NativeParent는 모든 소스 코드를 포함하고 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>
NativeTest1 년대와 NativeTest2의 리딩은 단지에 가지고있는 꽤 린 할 수 있습니다 parent-pom에서 diffeing 속성을 정의하십시오.
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>
서로 다른 패키지 형, 목표 이름과 컴파일 옵션이 있지만 대부분의 구성이에서 가져옵니다 만 가지 부모 폼.
하나의 compilerStartOption-Property 만 있으므로주의 깊게 살펴보면 child-pom에 동일한 이름의 여러 속성을 사용할 수 있기 때문에 부모 -pom의 모든 동등한 항목을 잃게됩니다.
나는 이것이 당신이 찾고 있던 종류이기를 바란다. 이것은 여전히 상용구 코드가 약간 있지만 크게 감소한 것이다.
감사합니다.이 작업을 수행 했음이 분명합니다 (약간 도움이 됨). 가장 많은 양의 상용구는 세 가지 '실행'목표의 반복에서 비롯됩니다.이 상위 수준의 접근 방식도 사용할 수 있습니까? – fommil
huzzah! http://stackoverflow.com/a/1256335/1041691 – fommil