簡體   English   中英

如何在模塊中導入 package (maven)

[英]How to import a package within modules (maven)

我有一個包含子模塊的 mvn 項目。 在其中一個模塊“moduleC”中,package“com.C.cto.wi.cipher.ssl”中有一個 class。 我需要能夠從 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>

模塊B 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 中有一個 class 需要訪問 package “com.C.cto.wi.cipher.ssl”中存在的類。

需要哪些 pom 修改才能實現這一點?

這取決於您的 pom 文件的結構,但您必須將 moduleC 作為依賴項包含在 moduleA 中。

此外,您已在 moduleC-info.java 中導出所需的 package:

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

最后,確保修改 moduleA-info.java :

requires moduleC;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM