如何在模块内导入包(Maven)

时间:2020-06-15 01:08:29

标签: java maven pom.xml

我有一个包含子模块的mvn项目。 在模块“ moduleC”之一中,包“ com.C.cto.wi.cipher.ssl”中存在一个类。我需要能够从moduleA内的类使用/调用它。

父pom:

<groupId>parent_groupId</groupId>
<artifactId>parent_artifactId</artifactId>
<version>parent_version</version>
<packaging>pom</packaging>
<name>parent_artifactId</name>

<modules>
    <module>moduleA</module>
    <module>moduleB</module>
</modules>

moduleB pom:

<parent>
    <groupId>parent_groupId</groupId>
    <artifactId>parent_artifactId</artifactId>
    <version>parent_version</version>
</parent>
<artifactId>moduleB</artifactId>
<packaging>pom</packaging>
<name>moduleB</name>
<modules>
    <module>moduleC</module>
</modules>  

现在,moduleC pom:

<parent>
    <groupId>parent_groupId</groupId>
    <artifactId>moduleB</artifactId>
    <version>parent_version</version>
</parent>
<artifactId>moduleC</artifactId>    
<packaging>bundle</packaging>
<name>moduleC</name>
<dependency>
// List of dependencies
</dependency>
<build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>                
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Bundle-SymbolicName>SomeName</Bundle-SymbolicName>
                        <Bundle-Name>SomeName</Bundle-Name>
                        <Bundle-Activator>someActivator</Bundle-Activator>
                        <Import-Package>org.osgi.framework</Import-Package>
                        <Export-Package>com.C.cto.wi.cipher.ssl</Export-Package>
                        <Embed-Dependency>
                        </Embed-Dependency>
                        <Embed-Transitive>true</Embed-Transitive>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
        <finalName>someName</finalName>
    </build>

现在,我在模块A中有一个类,该类需要访问包“ com.C.cto.wi.cipher.ssl”中存在的类。

要达到此目的需要什么pom修改?

1 个答案:

答案 0 :(得分:0)

这取决于pom文件的结构,但是必须将moduleC作为依赖项包含在moduleA中。

此外,您已经在模块C-info.java中导出了所需的软件包:

exports com.C.cto.wi.cipher.ssl;

最后,确保使用以下命令修改moduleA-info.java:

requires moduleC;
相关问题