1

我有一个示例/玩具 JNI 项目,我正在尝试使用 Maven 来管理和构建。子项目有:

  • MathFuncs : 纯本机代码 (C++)
  • JMathFuncsNative:在 JNI 中包装 MathFuncs 类的本机代码
  • JMathFuncs:加载 JMathFuncsNative 并调用其方法的 Java 存根代码
  • JHello:使用 JMathFuncs 的 Java 应用程序代码

每个项目应该只直接依赖于它上面的工件,并且应该对它上面的所有东西都有传递依赖。

当我mvn dependency:tree在每个项目上运行时:

  • MathFuncs 不依赖任何东西(正如预期的那样)。
  • JMathFuncsNative 依赖于 MathFuncs(如预期的那样):运行时为 dll,编译时为 lib 和 inczip。
  • JMathFuncs 依赖于 JMathFuncsNative(运行时范围),但不获取传递的 MathFuncs 依赖项。
  • JHello 依赖于一切(如预期的那样)。

当我mvn dependency:tree从父目录运行时:

  • MathFuncs 不依赖任何东西(正如预期的那样)。
  • JMathFuncsNative 依赖于 MathFuncs(如预期的那样):运行时为 dll,编译时为 lib 和 inczip。
  • JMathFuncs 依赖于 JMathFuncsNative(运行时范围),但不获取传递的 MathFuncs 依赖项。
  • JHello 依赖于 JMathFuncs(编译范围),它依赖于 JMathFuncsNative(运行时范围),但 MathFuncs 依赖项不存在。

谁能帮我解决这些依赖关系?

编辑:
这是 POM。我已经编辑了上面的项目名称以匹配下面的 POM 中显示的内容。

父 POM:

<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>com.mycompany.samples</groupId>
<artifactId>maven-test-sample</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
    <module>MathFuncs</module>
    <module>JMathFuncs</module>
    <module>JMathFuncsNative</module>
    <module>JHello</module>
</modules>
</project>

数学函数 POM:

<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.samples</groupId>
<artifactId>MathFuncs</artifactId>
<packaging>dll</packaging>
<version>1.0-SNAPSHOT</version>

<parent>
    <groupId>com.mycompany.samples</groupId>
    <artifactId>maven-test-sample</artifactId>
    <version>1.0-SNAPSHOT</version>
</parent>

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>native-maven-plugin</artifactId>
            <extensions>true</extensions>
            <version>1.0-alpha-7</version>

            <configuration>
                <compilerProvider>msvc</compilerProvider>
                <compilerStartOptions>
                    <compilerStartOption> /EHsc /W4</compilerStartOption>
                    <compilerStartOption>-D_WIN32_WINNT=0x0500</compilerStartOption>
                </compilerStartOptions>

                <sources>
                    <source>
                        <directory>src/main/native</directory>
                        <includes>
                            <include>**/*.cpp</include>
                            <include>**/*.c</include>
                        </includes>
                    </source>
                    <source>
                        <directory>src/main/native/include</directory>
                        <deployable>true</deployable>
                    </source>
                </sources>

                <linkerProvider>msvc</linkerProvider>
                <linkerSecondaryOutputExtensions>lib</linkerSecondaryOutputExtensions>
                <linkerStartOptions>
                    <linkerStartOption> /INCREMENTAL:NO /DLL </linkerStartOption>
                </linkerStartOptions>
            </configuration>

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

JMathFuncsNative POM:

<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/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.samples</groupId>
<artifactId>JMathFuncsNative</artifactId>
<packaging>dll</packaging>
<version>1.0-SNAPSHOT</version>

<parent>
    <groupId>com.mycompany.samples</groupId>
    <artifactId>maven-test-sample</artifactId>
    <version>1.0-SNAPSHOT</version>
</parent>

<dependencies>
    <dependency>
        <groupId>com.mycompany.samples</groupId>
        <artifactId>MathFuncs</artifactId>
        <version>1.0-SNAPSHOT</version>
        <scope>runtime</scope>
        <type>dll</type>
    </dependency>
    <dependency>
        <groupId>com.mycompany.samples</groupId>
        <artifactId>MathFuncs</artifactId>
        <version>1.0-SNAPSHOT</version>
        <scope>compile</scope>
        <type>lib</type>
    </dependency>
    <dependency>
        <groupId>com.mycompany.samples</groupId>
        <artifactId>MathFuncs</artifactId>
        <version>1.0-SNAPSHOT</version>
        <scope>compile</scope>
        <type>inczip</type>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>native-maven-plugin</artifactId>
            <extensions>true</extensions>
            <version>1.0-alpha-7</version>

            <configuration>
                <compilerProvider>msvc</compilerProvider>
                <compilerStartOptions>
                    <compilerStartOption> /EHsc /W4</compilerStartOption>
                    <compilerStartOption>-D_WIN32_WINNT=0x0500</compilerStartOption>
                </compilerStartOptions>

                <sources>
                    <source>
                        <directory>src/main/native</directory>
                        <includes>
                            <include>**/*.cpp</include>
                            <include>**/*.c</include>
                        </includes>
                    </source>
                    <source>
                        <directory>src/main/native/include</directory>
                        <deployable>true</deployable>
                    </source>
                    <source>
                        <directory>${java.home}\..\include</directory>
                    </source>
                    <source>
                        <directory>${java.home}\..\include\win32</directory>
                    </source>
                </sources>

                <linkerProvider>msvc</linkerProvider>
                <linkerSecondaryOutputExtensions>lib</linkerSecondaryOutputExtensions>
                <linkerStartOptions>
                    <linkerStartOption> /INCREMENTAL:NO /DLL </linkerStartOption>
                </linkerStartOptions>
            </configuration>

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

JMathFuncs POM:

<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>com.mycompany.samples</groupId>
    <artifactId>maven-test-sample</artifactId>
    <version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.mycompany.samples</groupId>
<artifactId>JMathFuncs</artifactId>
<version>1.0-SNAPSHOT</version>
<name>JMathFuncs</name>
<url>http://maven.apache.org</url>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>com.mycompany.samples</groupId>
        <artifactId>JMathFuncsNative</artifactId>
        <version>1.0-SNAPSHOT</version>
        <type>dll</type>
        <scope>runtime</scope>
    </dependency>
</dependencies>

</project>

JHello POM:

<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<modelVersion>4.0.0</modelVersion>

<parent>
    <groupId>com.mycompany.samples</groupId>
    <artifactId>maven-test-sample</artifactId>
    <version>1.0-SNAPSHOT</version>
</parent>

<groupId>com.mycompany.samples</groupId>
<artifactId>JHello</artifactId>
<version>1.0-SNAPSHOT</version>
<name>JHello</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>com.mycompany.samples</groupId>
        <artifactId>JMathFuncs</artifactId>
        <version>1.0-SNAPSHOT</version>
        <scope>compile</scope>
   </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.5.1</version>
            <executions>
                <execution>
                    <id>copy-libs</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}</outputDirectory>
                        <stripVersion>true</stripVersion>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
</project>

以及父目录的输出mvn dependency:tree

[INFO] Scanning for projects...  
[INFO] ------------------------------------------------------------------------  
[INFO] Reactor Build Order:  
[INFO]   
[INFO] maven-test-sample  
[INFO] MathFuncs  
[INFO] JMathFuncsNative  
[INFO] JMathFuncs  
[INFO] JHello  
[INFO]                                                                           
[INFO] ------------------------------------------------------------------------  
[INFO] Building maven-test-sample 1.0-SNAPSHOT  
[INFO] ------------------------------------------------------------------------  
[INFO]   
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ maven-test-sample ---  
[INFO] com.mycompany.samples:maven-test-sample:pom:1.0-SNAPSHOT  
[INFO]                                                                           
[INFO] ------------------------------------------------------------------------  
[INFO] Building MathFuncs 1.0-SNAPSHOT  
[INFO] ------------------------------------------------------------------------  
[INFO]   
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ MathFuncs ---  
[INFO] com.mycompany.samples:MathFuncs:dll:1.0-SNAPSHOT  
[INFO]                                                                           
[INFO] ------------------------------------------------------------------------  
[INFO] Building JMathFuncsNative 1.0-SNAPSHOT  
[INFO] ------------------------------------------------------------------------  
[INFO]   
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ JMathFuncsNative ---  
[INFO] com.mycompany.samples:JMathFuncsNative:dll:1.0-SNAPSHOT  
[INFO] +- com.mycompany.samples:MathFuncs:dll:1.0-SNAPSHOT:runtime  
[INFO] +- com.mycompany.samples:MathFuncs:lib:1.0-SNAPSHOT:compile  
[INFO] \- com.mycompany.samples:MathFuncs:inczip:1.0-SNAPSHOT:compile  
[INFO]                                                                           
[INFO] ------------------------------------------------------------------------  
[INFO] Building JMathFuncs 1.0-SNAPSHOT  
[INFO] ------------------------------------------------------------------------  
[INFO]   
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ JMathFuncs ---  
[INFO] com.mycompany.samples:JMathFuncs:jar:1.0-SNAPSHOT  
[INFO] \- com.mycompany.samples:JMathFuncsNative:dll:1.0-SNAPSHOT:runtime  
[INFO]                                                                           
[INFO] ------------------------------------------------------------------------  
[INFO] Building JHello 1.0-SNAPSHOT  
[INFO] ------------------------------------------------------------------------  
[INFO]   
[INFO] --- maven-dependency-plugin:2.5.1:tree (default-cli) @ JHello ---  
[INFO] com.mycompany.samples:JHello:jar:1.0-SNAPSHOT  
[INFO] \- com.mycompany.samples:JMathFuncs:jar:1.0-SNAPSHOT:compile  
[INFO]    \- com.mycompany.samples:JMathFuncsNative:dll:1.0-SNAPSHOT:runtime  
[INFO] ------------------------------------------------------------------------  
[INFO] Reactor Summary:  
[INFO]   
[INFO] maven-test-sample ................................. SUCCESS [0.905s]  
[INFO] MathFuncs ......................................... SUCCESS [0.327s]  
[INFO] JMathFuncsNative .................................. SUCCESS [0.063s]  
[INFO] JMathFuncs ........................................ SUCCESS [0.062s]  
[INFO] JHello ............................................ SUCCESS [0.546s]  
[INFO] ------------------------------------------------------------------------  
[INFO] BUILD SUCCESS  
[INFO] ------------------------------------------------------------------------  
[INFO] Total time: 2.777s  
[INFO] Finished at: Fri Nov 09 14:05:26 EST 2012  
[INFO] Final Memory: 10M/125M  
[INFO] ------------------------------------------------------------------------  
4

0 回答 0