多模块maven项目子模块不能引用其他模块的类

1.问题

子模块scnu-core中不能调用其他模块scnu-common的类。

本项目父模块为srb,scnu-common、scnu-base、scnu-core均为srb的子模块,且scnu-base引用scnu-common依赖、scnu-core引用scnu-base依赖。

2.解决方法

先查看父pom文件有没有定义子模块

父模块为:

    <groupId>com.scnu</groupId>
    <artifactId>srb</artifactId>
    <version>0.0.1-SNAPSHOT</version>

其子模块定义

    <modules>
        <module>scnu-common</module>
        <module>service-base</module>
        <module>service-core</module>
    </modules>

scnu-common、scnu-base、scnu-core每个模块都要有父模块的说明:

    <parent>
        <artifactId>srb</artifactId>
        <groupId>com.scnu</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

再查看子模块有没有引入对应的依赖

scnu-base:

        <dependency>
            <groupId>com.scnu</groupId>
            <artifactId>scnu-common</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

scnu-core:

        <dependency>
            <groupId>com.scnu</groupId>
            <artifactId>service-base</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

这时,如果scnu-core仍然不能引入scnu-common的类,则右键子模块scnu-core,选择Maven,选择Reimport解决问题。

ps:本文方法不具备通用性

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值