欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

IDEA项目的依赖(pom.xml文件)导入问题及解决

程序员文章站 2022-03-11 23:21:19
前言idea新建项目和pom.xml文件被修改时,右下角都会出现 maven projects need to be imported(项目需要导入依赖)如下,点击 import changes导入后...

前言

idea新建项目和pom.xml文件被修改时,右下角都会出现 maven projects need to be imported(项目需要导入依赖)

IDEA项目的依赖(pom.xml文件)导入问题及解决

如下,点击 import changes导入后,有时会一直处于加载中或导入失败

IDEA项目的依赖(pom.xml文件)导入问题及解决

解决方法

第一种方法:

右击pom.xml文件,选择maven中的reimport重新导入项目依赖,一般这种方法都解决不了上面的问题,可直接看下面的方法

IDEA项目的依赖(pom.xml文件)导入问题及解决

第二种方法:

点击 file 选择 settings… 直接搜索 maven,在搜索结果中 maven home directory:默认为bundled(maven 3),点击选择idea自带的maven,再点击应用–>ok,重新导入(第一种方法)即可

IDEA项目的依赖(pom.xml文件)导入问题及解决

IDEA项目的依赖(pom.xml文件)导入问题及解决

第三种方法:

若第二种方法还不能解决项目的依赖导入问题,则需要使用国内的maven类库,idea的maven类库默认都是使用国外的,一些地区由于墙的原因加载会很慢或者加载不了,此时可以导入阿里云的 maven 类库(一个settings_aliyun.xml文件)来使用,我就是用这个方法才解决的????????

pom.xml文件内容

<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"
 xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 <modelversion>4.0.0</modelversion>
 <groupid>com.tcl.kuyu.salesreport</groupid>
 <artifactid>salesreport-server</artifactid>
 <packaging>war</packaging>
 <version>1.0-snapshot</version>
 <name>salesreport-server</name>
 <url>http://maven.apache.org</url>

<!-- 刚开始的时候,我很不习惯,也不太理解为什么要用下面的标签,后来才觉得,代码就该这样。。。修改的时候也会特别的方便 -->
 <properties>
  <aspectj.version>1.8.9</aspectj.version>
  <java.version>1.8</java.version>
  <junit.version>4.12</junit.version>
  <logback.version>1.1.7</logback.version>
  <logback-ext-spring.version>0.1.4</logback-ext-spring.version>
  <mysql.driver.version>5.1.38</mysql.driver.version>
  <slf4j.version>1.7.21</slf4j.version>
  <spring.version>4.2.5.release</spring.version>
  <jackson.version>2.5.2</jackson.version>
  <mybatis.version>3.4.0</mybatis.version>
  <mybatis.spring.version>1.3.0</mybatis.spring.version>
  <mybatis-plus.version>1.2.16</mybatis-plus.version>
  <fastjson.version>1.2.11</fastjson.version>
  <shiro.version>1.2.6</shiro.version>
  <project.build.sourceencoding>utf-8</project.build.sourceencoding>
  <jetty.web.xml>${basedir}/jetty-webdefault.xml</jetty.web.xml>
 </properties>


 <dependencies>
  <!-- junit 此处是单元测试的依赖-->
  <dependency>
   <groupid>junit</groupid>
   <artifactid>junit</artifactid>
   <version>${junit.version}</version>
   <scope>test</scope>
  </dependency>

  <dependency>
   <groupid>junitperf</groupid>
   <artifactid>junitperf</artifactid>
   <version>1.8</version>
   <scope>test</scope>
  </dependency>

  <!-- spring -->
  <dependency>
   <groupid>org.springframework</groupid>
   <artifactid>spring-aop</artifactid>
   <version>${spring.version}</version>
  </dependency>

  <dependency>
   <groupid>org.springframework</groupid>
   <artifactid>spring-aspects</artifactid>
   <version>${spring.version}</version>
  </dependency>

  <dependency>
   <groupid>org.springframework</groupid>
   <artifactid>spring-beans</artifactid>
   <version>${spring.version}</version>
  </dependency>

  <dependency>
   <groupid>org.springframework</groupid>
   <artifactid>spring-context</artifactid>
   <version>${spring.version}</version>
  </dependency>

  <dependency>
   <groupid>org.springframework</groupid>
   <artifactid>spring-context-support</artifactid>
   <version>${spring.version}</version>
  </dependency>

  <dependency>
   <groupid>org.springframework</groupid>
   <artifactid>spring-core</artifactid>
   <version>${spring.version}</version>
  </dependency>

  <dependency>
   <groupid>org.springframework</groupid>
   <artifactid>spring-expression</artifactid>
   <version>${spring.version}</version>
  </dependency>

  <dependency>
   <groupid>org.springframework</groupid>
   <artifactid>spring-jdbc</artifactid>
   <version>${spring.version}</version>
  </dependency>

  <dependency>
   <groupid>org.springframework</groupid>
   <artifactid>spring-jms</artifactid>
   <version>${spring.version}</version>
  </dependency>

  <dependency>
   <groupid>org.springframework</groupid>
   <artifactid>spring-orm</artifactid>
   <version>${spring.version}</version>
  </dependency>

  <dependency>
   <groupid>org.springframework</groupid>
   <artifactid>spring-oxm</artifactid>
   <version>${spring.version}</version>
  </dependency>

  <dependency>
   <groupid>org.springframework</groupid>
   <artifactid>spring-test</artifactid>
   <version>${spring.version}</version>
   <scope>test</scope>
  </dependency>

  <dependency>
   <groupid>org.springframework</groupid>
   <artifactid>spring-tx</artifactid>
   <version>${spring.version}</version>
  </dependency>

  <dependency>
   <groupid>org.springframework</groupid>
   <artifactid>spring-web</artifactid>
   <version>${spring.version}</version>
  </dependency>

  <dependency>
   <groupid>org.springframework</groupid>
   <artifactid>spring-webmvc</artifactid>
   <version>${spring.version}</version>
  </dependency>

  <dependency>
   <groupid>commons-dbcp</groupid>
   <artifactid>commons-dbcp</artifactid>
   <version>1.4</version>
  </dependency>


  <!-- freemark  根据项目需要,简单的web项目的话此处是不需要的-->
  <dependency>
   <groupid>org.freemarker</groupid>
   <artifactid>freemarker</artifactid>
   <version>[2.3.19,2.4)</version>
  </dependency>

  <dependency>
   <groupid>commons-httpclient</groupid>
   <artifactid>commons-httpclient</artifactid>
   <version>3.1</version>
  </dependency>

  <dependency>
   <groupid>org.apache.commons</groupid>
   <artifactid>commons-lang3</artifactid>
   <version>3.1</version>
  </dependency>

   <dependency>
    <groupid>commons-collections</groupid>
    <artifactid>commons-collections</artifactid>
    <version>3.2.2</version>
   </dependency>

   <dependency>
    <groupid>com.alibaba</groupid>
    <artifactid>fastjson</artifactid>
    <version>${fastjson.version}</version>
   </dependency>

  <!-- logback begin -->
  <dependency>
   <groupid>org.slf4j</groupid>
   <artifactid>slf4j-api</artifactid>
   <version>${slf4j.version}</version>
  </dependency>

  <dependency>
   <groupid>ch.qos.logback</groupid>
   <artifactid>logback-core</artifactid>
   <version>${logback.version}</version>
  </dependency>

  <dependency>
   <groupid>ch.qos.logback</groupid>
   <artifactid>logback-classic</artifactid>
   <version>${logback.version}</version>
  </dependency>
  <!-- logback end -->

  <dependency>
   <groupid>org.aspectj</groupid>
   <artifactid>aspectjrt</artifactid>
   <version>${aspectj.version}</version>
  </dependency>
  <dependency>
   <groupid>org.aspectj</groupid>
   <artifactid>aspectjweaver</artifactid>
   <version>${aspectj.version}</version>
  </dependency>

  <dependency>
   <groupid>mysql</groupid>
   <artifactid>mysql-connector-java</artifactid>
   <version>${mysql.driver.version}</version>
  </dependency>

  <dependency>
   <groupid>org.mybatis</groupid>
   <artifactid>mybatis</artifactid>
   <version>${mybatis.version}</version>
  </dependency>
  <dependency>
   <groupid>org.mybatis</groupid>
   <artifactid>mybatis-spring</artifactid>
   <version>${mybatis.spring.version}</version>
  </dependency>
   <dependency>
    <groupid>com.baomidou</groupid>
    <artifactid>mybatis-plus</artifactid>
    <version>${mybatis-plus.version}</version>
   </dependency>

  <dependency>
   <groupid>com.fasterxml.jackson.core</groupid>
   <artifactid>jackson-databind</artifactid>
   <version>${jackson.version}</version>
  </dependency>

  <dependency>
   <groupid>com.fasterxml.jackson.core</groupid>
   <artifactid>jackson-core</artifactid>
   <version>${jackson.version}</version>
  </dependency>

  <dependency>
   <groupid>commons-fileupload</groupid>
   <artifactid>commons-fileupload</artifactid>
   <version>1.3.1</version>
  </dependency>

  <dependency>
   <groupid>javax.servlet.jsp</groupid>
   <artifactid>jsp-api</artifactid>
   <version>2.2</version>
   <scope>provided</scope>
  </dependency>

  <dependency>
   <groupid>javax.servlet</groupid>
   <artifactid>servlet-api</artifactid>
   <version>2.5</version>
   <scope>provided</scope>
  </dependency>

 <dependency>
  <groupid>com.mangofactory</groupid>
  <artifactid>swagger-springmvc</artifactid>
  <version>1.0.2</version>
 </dependency>

 <dependency>
  <groupid>com.fasterxml.jackson.core</groupid>
  <artifactid>jackson-annotations</artifactid>
  <version>${jackson.version}</version>
 </dependency>

   <dependency>
    <groupid>com.alibaba</groupid>
    <artifactid>druid</artifactid>
    <version>1.0.18</version>
   </dependency>

   <dependency>
    <groupid>javassist</groupid>
    <artifactid>javassist</artifactid>
    <version>3.12.1.ga</version>
   </dependency>

   <!-- shiro权限管理 -->
   <dependency>
     <groupid>org.apache.shiro</groupid>
     <artifactid>shiro-core</artifactid>
     <version>${shiro.version}</version>
   </dependency>
   <dependency>
     <groupid>org.apache.shiro</groupid>
     <artifactid>shiro-web</artifactid>
     <version>${shiro.version}</version>
   </dependency>
   <!-- 如果要与spring集成,需要添加此依赖 -->
   <dependency>
     <groupid>org.apache.shiro</groupid>
     <artifactid>shiro-spring</artifactid>
     <version>${shiro.version}</version>
   </dependency>
   <!-- shiro权限管理 -->

  </dependencies>

 <build>
  <finalname>salesreport</finalname>

<!--下面的resources里面的配置,大家可以根据自身项目需要进行选择和修改-->
  <resources>
   <resource>
    <directory>src/main/resources/commons</directory>
    <filtering>true</filtering>
    <includes>
     <include>**/*.*</include>
    </includes>
   </resource>
   <resource>
    <directory>src/main/resources/${env}</directory>
    <filtering>true</filtering>
    <includes>
     <include>**/*.*</include>
    </includes>
   </resource>
  </resources>

  <plugins>
   
  <!-- 编译插件 -->  
  <plugin>
    <artifactid>maven-compiler-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

IDEA项目的依赖(pom.xml文件)导入问题及解决

按第一种方法重新导入一下即可

IDEA项目的依赖(pom.xml文件)导入问题及解决

至此,sync出现绿√即导入项目依赖成功啦!

到此这篇关于idea项目的依赖(pom.xml文件)导入问题及解决的文章就介绍到这了,更多相关idea pom.xml文件导入内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!