怎么在maven中利用解决pom.xml的版本问题

怎么在maven中利用<exclusion>解决pom.xml的版本问题?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

详解 maven的pom.xml用<exclusion>解决版本问题

    用maven管理库依赖,有个好处就是连同库的依赖的全部jar文件一起下载,免去手工添加的麻烦,但同时也带来了同一个jar会被下载了不同版本的问题,好在pom的配置里面允许用<exclusion>来排除一些不需要同时下载的依赖jar 。

      比如配置struts-core,它会同时下载javassist和asm相关的jar,但版本又不够新,这时可以排除它们:

<!-- Struts2 --> 
    <dependency> 
      <groupId>org.apache.struts</groupId> 
      <artifactId>struts2-core</artifactId> 
      <version>${struts.version}</version> 
      <exclusions> 
        <exclusion> 
          <groupId>javassist</groupId> 
          <artifactId>javassist</artifactId> 
        </exclusion> 
        <exclusion> <!-- we prefer our explicit version, though it should be the same --> 
          <groupId>asm</groupId> 
          <artifactId>asm</artifactId> 
        </exclusion> 
        <exclusion> <!-- we prefer our explicit version, though it should be the same --> 
          <groupId>asm</groupId> 
          <artifactId>asm-commons</artifactId> 
        </exclusion> 
        <exclusion> <!-- we prefer our explicit version, though it should be the same --> 
          <groupId>org.ow2.asm</groupId> 
          <artifactId>asm</artifactId> 
        </exclusion> 
        <exclusion> <!-- we prefer our explicit version, though it should be the same --> 
          <groupId>org.ow2.asm</groupId> 
          <artifactId>asm-commons</artifactId> 
        </exclusion> 
      </exclusions> 
    </dependency> 

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注行业资讯频道,感谢您对亿速云的支持。