eclipse把maven配置引入本地jar包,打war包时打到lib

正常<scope>system</scope>的依赖是不会打进包的

假设项目中有个jar包(gson-2.8.5.jar)需要通过<scope>system</scope>的形式打包

如果你的项目打的是jar包

复制代码
    <packaging>jar</packaging>

那么配置<includeSystemScope>true</includeSystemScope>就可以把jar打进去

复制代码
<plugins> 
  <plugin> 
    <groupId>org.springframework.boot</groupId>  
    <artifactId>spring-boot-maven-plugin</artifactId>  
    <configuration> 
      <includeSystemScope>true</includeSystemScope> 
    </configuration> 
  </plugin> 
</plugins>

如果你的项目打的是war包

复制代码
 <packaging>war</packaging>

如果配置了<includeSystemScope>true</includeSystemScope>

打war包不会将本地jar包打入\WEB-INF\lib 下,而是在 \WEB-INF\lib-provided 下

需要在 <build> <plugins> 下添加或修改maven-war-plugin配置

<directory></directory> 内为你项目里存放lib的路径,这里是src/main/resources/lib

<targetPath></targetPath> 是目标路径,打入 WEB-INF/lib/

<include></include> 所有jar包

复制代码
 <plugin> 
    <groupId>org.apache.maven.plugins</groupId>  
    <artifactId>maven-war-plugin</artifactId>  
    <configuration> 
      <webResources> 
        <resource> 
          <directory>src/main/resources/lib</directory>  
          <targetPath>WEB-INF/lib/</targetPath>  
          <includes> 
            <include>**/*.jar</include> 
          </includes> 
        </resource> 
      </webResources> 
    </configuration> 
  </plugin> 

附:maven配置引入本地jar包

假设项目中需要引入本地ar包(gson-2.8.5.jar)

首先配置一个基础路径

复制代码
<properties>
    <locallib.path>${project.basedir}/src/main/resources/lib</locallib.path>
</properties>

然后配置项目路径中的jar包

复制代码
<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.8.5</version>
    <scope>system</scope>
    <systemPath>${locallib.path}/gson-2.8.5.jar</systemPath>
</dependency>

或者直接指定路径

复制代码
		<!-- 浙江政务2.0 -->
        <dependency>
            <groupId>com.alibaba.gov</groupId>
            <artifactId>atg-sdk-java</artifactId>
            <version>RELEASE20210107143535</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/src/main/resources/lib/atg-sdk-java-RELEASE20210107143535.jar</systemPath>
        </dependency>

加了plugin之后可能会报错

相关推荐
蚂蚁雅嘿11 小时前
maven标签日常总结
java·maven
菠萝加点糖12 小时前
Maven 坐标系统说明
java·maven
hm宋12 小时前
Canal 升级 jar 包操作文档(以升级 FastJSON 为例)
java·canal·jar
砚底藏山河17 小时前
拉数管道设计:从一次性脚本到可重启的数据流水线(魔码量化实战 #01)
java·数据库·python·金融·maven
卓怡学长2 天前
w157基于springboot北部湾地区助农平台
java·spring boot·spring·maven·intellij-idea
老猿讲编程2 天前
【Eclipse OpenSOVD学习之二】 SOVD 协议原理与标准背景
学习·eclipse·嵌入式软件·车载·sovd
程序员良辰2 天前
Eclipse Memory Analyzer(MAT)入门教程:从生成 Heap Dump 到定位 Java 内存问题
java·ide·eclipse·tomcat·idea
pjj198542 天前
Hadoop-python中使用大数据1
java·ide·eclipse
IT界的老黄牛2 天前
Jenkins 构建卡了 23 天,abort 按钮点了没用
jenkins·maven·prometheus·告警·排查·ci-cd
卓怡学长3 天前
w156一周穿搭App的设计与实现
java·spring boot·spring·maven·intellij-idea