在maven项目中的模块内共享类

时间:2014-12-10 16:27:08

标签: java maven multi-module

首先,我是maven的新手,很抱歉这个问题太简单了:)

我有主要模块" main" 和子模块:a,b,c,...

我想要的是与子模块b共享子模块a中的一些数据。

父pom看起来像:         4.0.0

    <groupId>Parent</groupId>
    <artifactId>Parent</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>

    <modules>
        <module>a</module>
        <module>b</module>
        <module>c</module>
    </modules>
</project>

我想分享的孩子看起来像:

<parent>
    <artifactId>Parent</artifactId>
    <groupId>Parent</groupId>
    <version>1.0-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>a</artifactId>
</project>

和&#34;消费者&#34;孩子看起来像:

<parent>
        <artifactId>Parent</artifactId>
        <groupId>Parent</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>b</artifactId>

    <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>a</artifactId>
            <version>${project.version}</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
    </dependencies>

我确实看到jar文件被添加到&#34;外部库&#34; (我使用的是Intellij) 但是jar只包含没有代码的META-INF文件夹(可以吗?)

故事结束,我不能在ChildB类中使用Class ChildA ... 任何帮助都应该得到帮助!!

1 个答案:

答案 0 :(得分:1)

问题在于我已经&#34; btoken&#34; maven的项目结构.... 一旦我构建了应该由maven创建的模块,就像魅力一样:) http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html