pom文件依赖<scope>system</scope> 打包不依赖 解决方案

本文详细介绍了Maven中依赖范围(scope)的概念及其不同选项的作用,包括compile、test、runtime、provided和system,并提供了如何处理系统路径依赖的具体解决方案。
//例子
<scope>system</scope>
//应用外置jar包
<dependency>
    <groupId>jeewx</groupId>
    <artifactId>jeewx</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/jeewx-1.0.jar</systemPath>
</dependency>

scope  maven中scope的默认值是compile

scope的分类

1)compile 默认是compile。compile表示被依赖项目需要参与当前项目的编译,包括后续的测试,运行周期也参与其中,是一个比较强的依赖。打包的时候通常需要包含进去。

2)test 表示依赖项目仅仅参与测试相关的工作,包括测试代码的编译,执行。比较典型的如junit

3)runtime 表示被依赖项目无需参与项目的编译,不过后期的测试和运行周期需要其参与。与compile相比,跳过编译而已。在终端的项目(非开源,企业内部系统)中,和compile区别不是很大。比较常见的如JSRXXX的实现,对应的API jar是compile,具体实现是runtime的,compile只需要知道接口就足够了。oracle jdbc驱动jar包就是一个很好的例子,一般scope为runtime。  另runtime的依赖通常和optional搭配使用,optional为true。即可以用A实现也可以用B实现。

4)procided 意味着打包的时候可以不用包进去,别的设施(web container)会提供。事实上该依赖理论上可以参与编译、测试、运行等周期。相当于compile,但是打包阶段做了exclude的动作。

5)system 和provide相同,不过被依赖项不会从maven仓库抓,而是从本地系统文件拿,一定要配合systemPath使用

 

systempath

当maven依赖本地而非repository中的jar包,sytemPath指明本地jar包路径


解决方案一:

将本地应用的jar包上传值公司私服(需要去改maven的私服地址)然后常规应用

<dependency>
    <groupId>jeewx</groupId>
    <artifactId>jeewx</artifactId>
    <version>1.0</version>
</dependency>

解决方案二:

将自己需要依赖的jar 打包到本地maven 库 (前提的配置好本地mvn)

打开cmd 窗口 输入

mvn install:install-file -Dfile=c:/xxx/xxx.jar -DgroupId=jeewx -DartifactId=jeewx-Dversion=1.0 -Dpackaging=jar  


 

解决方案三:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <includeSystemScope>true</includeSystemScope>
    </configuration>
</plugin>

解决方案四:

修改 xxxx.MF文件 里面的jar引用 加上自己需要的jar包 按空格分隔 (这种有个大问题是每次都得改xxx.MF文件不太方便)

 

<?xml version="1.0" encoding="UTF-8"?> <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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.7.11</version> <relativePath/> </parent> <groupId>com.hw</groupId> <artifactId>asset</artifactId> <version>1.0.0</version> <name>asset</name> <description>asset</description> <properties> <java.version>8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </dependency> <dependency> <groupId>com.oracle.database.jdbc</groupId> <artifactId>ojdbc8</artifactId> <version>21.15.0.0</version> </dependency> <dependency> <groupId>com.huawei.gauss</groupId> <artifactId>com.huawei.gauss.jdbc.ZenithDriver</artifactId> <version>V300R001C00CP2075B060</version> <scope>system</scope> <systemPath>${project.basedir}/lib/gaussdbv3.jdbc-V300R001C00CP2075.jar</systemPath> </dependency> </dependencies> <profiles> <!-- 开发环境 --> <profile> <id>dev</id> <properties> <activatedProperties>dev</activatedProperties> </properties> <activation> <activeByDefault>true</activeByDefault> <!-- 默认激活 --> </activation> </profile> <!-- 测试环境 --> <profile> <id>test</id> <properties> <activatedProperties>test</activatedProperties> </properties> </profile> <!-- 生产环境 --> <profile> <id>prod</id> <properties> <activatedProperties>prod</activatedProperties> </properties> </profile> </profiles> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> </configuration> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> </configuration> </plugin> </plugins> </build> </project> 为什么打包lib的文件没有打进去呢?
07-17
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值