前言
IDEA新建项目和pom.xml文件被修改时,右下角都会出现 Maven projects need to be imported(项目需要导入依赖)
如下,点击 Import Changes导入后,有时会一直处于加载中或导入失败
解决方法
第一种方法:
右击pom.xml文件,选择Maven中的Reimport重新导入项目依赖,一般这种方法都解决不了上面的问题,可直接看下面的方法
第二种方法:
点击 File 选择 Settings… 直接搜索 Maven,在搜索结果中 Maven home directory:默认为Bundled(Maven 3),点击选择IDEA自带的Maven,再点击应用–>OK,重新导入(第一种方法)即可
第三种方法:
若第二种方法还不能解决项目的依赖导入问题,则需要使用国内的Maven类库,IDEA的Maven类库默认都是使用国外的,一些地区由于墙的原因加载会很慢或者加载不了,此时可以导入阿里云的 Maven 类库(一个settings_aliyun.xml文件)来使用,我就是用这个方法才解决的😂😂
pom.xml文件内容
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://piler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> <!-- 单元测试插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.19</version> <configuration> <skipTests>true</skipTests> </configuration> </plugin> <!--jetty 插件,mvn jetty:run --> <plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>9.3.7.v20160115</version> <configuration> <webApp> <webDefaultXml>${jetty.web.xml}</webDefaultXml> <contextPath>/</contextPath> <descriptor>${basedir}/src/main/webapp/WEB-INF/web.xml</descriptor> </webApp> <stopKey>exit</stopKey> <stopPort>9091</stopPort> <webAppSourceDirectory>${project.basedir}/src/main/webapp</webAppSourceDirectory> <scanIntervalSeconds>0</scanIntervalSeconds> <httpConnector> <port>8080</port> </httpConnector> </configuration> </plugin> </plugins> </build> <profiles> <profile> <id>dev</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <env>dev</env> </properties> </profile> <profile> <id>sit</id> <properties> <env>sit</env> </properties> </profile> <profile> <id>prod</id> <properties> <env>prod</env> </properties> </profile> <profile> <id>uat</id> <properties> <env>uat</env> </properties> </profile> </profiles> </project>导入xml文件:进入第二种方法的 Maven 界面勾选右侧第一个Override
按第一种方法重新导入一下即可
至此,Sync出现绿√即导入项目依赖成功啦!
到此这篇关于IDEA项目的依赖(pom.xml文件)导入问题及解决的文章就介绍到这了,更多相关IDEA pom.xml文件导入内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!