首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在模块中导入包(maven)

问如何在模块中导入包(maven)
EN

Stack Overflow用户
提问于 2020-06-15 09:08:29
回答 1查看 614关注 0票数 0

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

父pom:

代码语言:javascript
复制
<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:

代码语言:javascript
复制
<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:

代码语言:javascript
复制
<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进行哪些修改才能实现这一点?

EN

回答 1

Stack Overflow用户

发布于 2020-06-15 11:14:53

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

另外,您已经在moduleC-info.java中导出了所需的包:

代码语言:javascript
复制
exports com.C.cto.wi.cipher.ssl;

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

代码语言:javascript
复制
requires moduleC;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62379927

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档