【报错】程序包com.xx.xx不存在

一、 报错内容

  1. 程序包com.xx.xx不存在
  2. 找不到符号

二、 报错场景

项目结构如下: – parent      //父项目 ------ children1    //同级子项目 ------ children2    //同级子项目

因为我在children1的pom中引入了children2项目依赖,并且children1注入了children2中的类,所以使该类注入和调用的地方出现如上图的报错。 在网上苦苦搜寻后,罗列了下可能能够解决该报错的方法。

解决办法一

在common子工程下的pom.xml,添加以下配置:

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <classifier>exec</classifier>
                </configuration>
            </plugin>
        </plugins>
</build>

解决方法二

添加<system>和<systemPath>两行内容:

<dependency>
            <groupId>com.xx.xx</groupId>
            <artifactId>kafka_producer</artifactId>
            <version>0.0.1-SNAPSHOT</version>

            <scope>system</scope>
            <systemPath>${project.basedir}/src/main/resources/lib/kafka_producer-0.0.1-SNAPSHOT.jar</systemPath>
        </dependency>

并在<build>中添加<includeSystemScope>true</includeSystemScope>:

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
            </plugin>
        </plugins>
    </build>

解决方法三

把项目文件夹中的.idea文件夹删掉

三、 报错解决

但真正解决我问题的解决方式还是去掉<build>中的内容,如图,我去掉了父pom中的如下内容(如果在被别的模块引用了或者被引用,建议依赖的模块中也要把这个插件删掉):

经验分享 程序员 微信小程序 职场和发展