Springboot项目在pom引入新包后,加载后还是报程序包不存在
项目中需要加入redis,就在pom中引入相应的依赖
reload后只能运行一次成功,后面就报程序包不存在,想重新跑得重启idea再reload,挺费劲的,不能每次都这么操作
后来查了下资料,是 intellij idea的工程配置文件.iml关于maven配置信息没有得到更新
所以要更新一下这个文件
步骤如下:
1.删除这个文件
2.在Terminal敲命令mvn idea:module重新生成.iml文件
(有的可以直接敲命令mvn idea:module重新生成,但我这边试了不行,不知道为啥,可以先试一下这个省很多后续问题)
好了后我这边又连续出现了两个问题
问题1.项目引不进来
查看一下生成的.iml是不是我的 项目名.iml,改成 项目名.iml,然后项目就正常了
问题2.发现关于maven窗口和maven相关的操作都没了,应该是项目不是maven项目了
查了一下.iml文件,里面引的jar包全部是绝对路径,根本不是maven的动态路径,是下面这个样子
<orderEntry type="module-library"> <library> <CLASSES> <root url="jar://D:/apache-maven-3.3.9/repository/com/fasterxml/jackson/module/jackson-module-parameter-names/2.11.4/jackson-module-parameter-names-2.11.4.jar!/"/> </CLASSES> </library> </orderEntry> <orderEntry type="module-library"> <library> <CLASSES> <root url="jar://D:/apache-maven-3.3.9/repository/org/springframework/boot/spring-boot-starter-tomcat/2.4.5/spring-boot-starter-tomcat-2.4.5.jar!/"/> </CLASSES> </library> </orderEntry> <orderEntry type="module-library"> <library> <CLASSES> <root url="jar://D:/apache-maven-3.3.9/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.45/tomcat-embed-core-9.0.45.jar!/"/> </CLASSES> </library> </orderEntry>
需要把项目改成maven项目
步骤:help->FindAction,输入Maven Projects,就会出现一个“+ Add Maven Projects”选项,点击后,右侧的maven窗口就会出现了。
.iml文件内容也变成这样了
<orderEntry type="module-library"> <library> <CLASSES> <root url="jar://$MAVEN_REPOSITORY$/org/projectlombok/lombok/1.18.20/lombok-1.18.20.jar!/" /> </CLASSES> <JAVADOC /> <SOURCES /> </library> </orderEntry> <orderEntry type="module-library"> <library> <CLASSES> <root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-configuration-processor/2.4.5/spring-boot-configuration-processor-2.4.5.jar!/" /> </CLASSES> <JAVADOC /> <SOURCES /> </library> </orderEntry> <orderEntry type="module-library"> <library> <CLASSES> <root url="jar://$MAVEN_REPOSITORY$/com/alibaba/druid-spring-boot-starter/1.1.22/druid-spring-boot-starter-1.1.22.jar!/" /> </CLASSES> <JAVADOC /> <SOURCES /> </library> </orderEntry>