Maven imports private jar packages (oracle11g)

Maven imports private jar packages

In the development project, some jars are developed by ourselves. When they are referenced to other projects or projects, the jars developed by ourselves need to be added to other projects.

  • Maven imports the private jar package to be loaded in the systemPath mode, and is packaged in the resouces mode

  • The packaged lib is generally under BOOT-INF\lib in the jar , you can check whether your own jar is imported by yourself!

load

Here take the oracle package as an example, the jar package of ojdbc6 is under the lib of the project root path

Add the configuration in the pom.xml file as follows:

<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>ojdbc6</artifactId>
    <version>11.2.0.1.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/lib/ojdbc6-11.2.0.1.0.jar</systemPath>
</dependency>

explain:

  • groupId: Organization name, preferably consistent with the internal package structure of the jar package;

  • artifactId: Organization name, this should be consistent with the name of the loaded jar (ojdbc6-11.2.0.1.0.jar), the name of the jar I want to load is ojdbc6-11.2.0.1.0.jar), the artifactId name is usually not added The version number, artifactId name and loaded jar name are kept below, so the name of artifactId can be defined as ojdbc6

  • version: jar version number, preferably consistent with the loaded jar, the name of the loaded jar is ojdbc6-11.2.0.1.0.jar, and the version number is the number after it. This can be modified, but the version cannot be lost.

Pack

The pom resource file needs to be introduced

The resources configuration needs to be added to the pom.xml file as follows:

<build>
    <!-- 最终打包名称:rest-boot.jar -->
	<finalName>rest-boot</finalName>
	<resources>
		<resource>
			<directory>src/main/java</directory><!--java文件的路径-->
			<includes>
				<include>**/*.*</include>
			</includes>
			<!-- <filtering>false</filtering>-->
		</resource>
		<resource>
			<directory>src/main/resources</directory><!--资源文件的路径-->
			<includes>
				<include>**/*.*</include>
			</includes>
			<!-- <filtering>false</filtering>-->
		</resource>
		<!-- 加入如下配置,吧jar包以资源形式打包进指定路径 -->
		<resource>
			<directory>${project.basedir}/lib</directory>
			<targetPath>BOOT-INF/lib/</targetPath>
			<includes>
				<include>**/*.jar</include>
			</includes>
		</resource>
	</resources>

	<plugins>
		<!-- spring-boot-maven-plugin (提供了直接运行项目的插件:如果是通过parent方式继承spring-boot-starter-parent则不用此插件) -->
		<plugin>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-maven-plugin</artifactId>
			<version>${spring-boot.version}</version>
			<executions>
				<execution>
					<goals>
						<goal>repackage</goal>
					</goals>
				</execution>
			</executions>
		</plugin>
	</plugins>
</build>

Summarize

The above is what I want to talk about today. This article only briefly introduces the use of maven to import private jar packages. If you like it, collect it and give it a thumbs up!

Guess you like

Origin blog.csdn.net/weixin_44571055/article/details/128581710