Maven打包项目为依赖包、及包引用

一 : maven配置

1.1、原配置

在这里插入图片描述

<build>
	<plugins>
		<plugin>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-maven-plugin</artifactId>
			<configuration>
				<mainClass>SecretApplication</mainClass>
			</configuration>
		</plugin>
	</plugins>
</build>

maven打包,jar包如下:
在这里插入图片描述

1.2、更改配置

在这里插入图片描述

<build>
	<plugins>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-compiler-plugin</artifactId>
			<configuration>
				<source>1.8</source>
				<target>1.8</target>
			</configuration>
		</plugin>
		<!--<plugin>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-maven-plugin</artifactId>
			<configuration>
				<mainClass>SecretApplication</mainClass>
			</configuration>
		</plugin>-->
	</plugins>
</build>

maven重新打包,jar包如下:
在这里插入图片描述
该jar包可提供第三方引用。

二 : jar包引用

以上面jar包为例:secret-1.0.0.jar

2.1、引入maven仓库

可将jar包放入自己的maven仓库内,通过pom文件引入

<dependency>
	<groupId>secret</groupId>
	<artifactId>secret</artifactId>
	<version>1.0.0</version>
</dependency>

2.2、手动引入(更方便)

在项目的根目录新建一个lib目录,将(secret-1.0.0.jar)放置在该目录。
在pom文件中配置

<dependency>
    <groupId>secret</groupId>
    <artifactId>secret</artifactId>
    <version>1.0.0</version>
    <scope>system</scope>
    <systemPath>${
    
    project.basedir}/lib/secret-1.0.0.jar</systemPath>
</dependency>

猜你喜欢

转载自blog.csdn.net/qq_38254635/article/details/131800967