scope标签的值的种类:
1、compile:默认值,可省略不写。表示该依赖需要参与到项目的编译、测试以及运行周期中,打包时也要包含进去。
2、test:该依赖仅仅参与测试相关的工作,包括测试代码的编译和执行,非测试代码部分不参与编译、运行,不会被打包,例如:junit。
3、runtime:该依赖无需参与项目的编译,项目的测试和运行需要其参与。与compile相比,跳过了编译而已,会被打包进去。例如JDBC驱动,适用运行和测试阶段。
4、provided:事实上该依赖理论上可以参与编译,测试,运行等周期。相当于compile,但是打包阶段做了exclude(排除)操作,不会被打包。
5、system:从参与度来说,和provided相同,不过被依赖项不会从maven仓库下载,而是从本地文件系统拿。需要添加systemPath的属性来定义路径。
6、import:import只能用在dependencyManagement块中,Maven不能多继承,常用来项目既想继承A工程又想继承B工程。如微服务同时继承Spring Boot、Spring Cloud、Spring Cloud Alibaba三个父工程。
Maven引入本地jar包
项目中com.sun.image.codec.jpeg.JPEGCodec用到了rt.jar包,jar包是本地jar包,有2种引入方式,推荐方式一。
方式一:
在 <build>插件中直接引入。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArguments>
<!--如果引用多个jar需要使用;(windows)或者:(macos)来分割,多个平台下开发会很不方便,可以使用变量path.separator代替-->
<bootclasspath>${java.home}/lib/rt.jar${path.separator}${java.home}/lib/jce.jar</bootclasspath>
</compilerArguments>
</configuration>
</plugin>
方式二
使用system标签引入本地jar包
<!--com.sun.image.codec.jpeg.JPEGCodec用到了rt.jar-->
<dependency>
<groupId>jdk.rt</groupId>
<artifactId>jdk.rt</artifactId>
<version>1.8</version>
<scope>system</scope>
<systemPath>${java.home}/lib/rt.jar</systemPath>
<!--<systemPath>${basedir}/webapp/WEB-INF/lib/rt.jar</systemPath>-->
</dependency>
<fork>true</fork>表示它将创建(fork)一个新的JVM来运行编译器。这有点慢,但隔离效果更好。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArgs>
<arg>-XDignore.symbol.file</arg>
</compilerArgs>
<fork>true</fork>
</configuration>
</plugin>