maven打包插件maven-jar-plugin

李嘉胜
2023-12-01

个人博客导航页(点击右侧链接即可打开个人博客):大牛带你入门技术栈 

项目打包需求描述

1、导出单独的项目jar包(精简,不包含依赖jar)
2、项目依赖的所有jar包导出到lib目录下
3、项目依赖oracle ojdbc8.jar,在maven仓库中并不存在,需要一并导出并添加进MANIFEST.MF文件中的Class-Path。
--也可以将ojdbc8安装到本地maven仓库后直接导出
工程目录:

maven pom.xml

<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
    http://maven.apache.org/xsd/maven-4.0.0.xsd">

	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>cn.xk.dp</groupId>
		<artifactId>thirdparty</artifactId>
		<version>0.0.1-SNAPSHOT</version>
	</parent>
	<artifactId>weixin-api</artifactId>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<log4j.version>2.13.0</log4j.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
			<version>1.7.30</version>
		</dependency>
		<dependency>
			<groupId>org.apache.logging.log4j</groupId>
			<artifactId>log4j-core</artifactId>
			<version>${log4j.version}</version>
		</dependency>

		<dependency>
			<groupId>org.apache.logging.log4j</groupId>
			<artifactId>log4j-slf4j-impl</artifactId>
			<version>${log4j.version}</version>
		</dependency>

		<dependency>
			<groupId>org.apache.httpcomponents</groupId>
			<artifactId>httpclient</artifactId>
			<version>4.5.11</version>
			<exclusions>
				<exclusion>
					<groupId>commons-logging</groupId>
					<artifactId>commons-logging</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>jcl-over-slf4j</artifactId>
			<version>1.7.30</version>
		</dependency>

		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>fastjson</artifactId>
			<version>1.2.66</version>
		</dependency>
		<dependency> <!--添加本地jar包依赖-->
   			<groupId>oracle</groupId> 
   			<artifactId>ojdbc8</artifactId> 
   			<version>1.0</version> 
   			<scope>system</scope> 
   			<systemPath>${pom.basedir}/lib/ojdbc8.jar</systemPath> 
		</dependency>
	</dependencies>

	<build>
		<plugins>
		 <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.2.0</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <useUniqueVersions>false</useUniqueVersions>
                            <classpathPrefix>lib/</classpathPrefix>
                            <mainClass>cn.xk.dp.weixin.Driver</mainClass>
                        </manifest>
                        <manifestEntries>  <!--将ojdbc8-1.0.jar写进MANIFEST.MF文件中的Class-Path-->
   				           <Class-Path>lib/ojdbc8-1.0.jar</Class-Path>
  			            </manifestEntries> 
                    </archive>
                    <excludes>   <!--排除用于测试的日志配置资源文件-->
                        <exclude>log4j2-test.xml</exclude>
                    </excludes>
                </configuration>
           </plugin>
		<plugin>  <!--在打包阶段将依赖的jar包导出到lib目录下-->
		  <groupId>org.apache.maven.plugins</groupId>
		  <artifactId>maven-dependency-plugin</artifactId>
		  <executions>
		    <execution>
			<id>copy-dependencies</id>
                        <phase>package</phase>
			<goals>
			  <goal>copy-dependencies</goal>
			</goals>
			<configuration>
			  <type>jar</type>
			  <includeTypes>jar</includeTypes>
	          <outputDirectory>${project.build.directory}/lib</outputDirectory>
			</configuration>
		    </execution>
		  </executions>
	     </plugin>
      </plugins>
	</build>
</project>

附Java/C/C++/机器学习/算法与数据结构/前端/安卓/Python/程序员必读/书籍书单大全:

(点击右侧 即可打开个人博客内有干货):技术干货小栈
=====>>①【Java大牛带你入门到进阶之路】<<====
=====>>②【算法数据结构+acm大牛带你入门到进阶之路】<<===
=====>>③【数据库大牛带你入门到进阶之路】<<=====
=====>>④【Web前端大牛带你入门到进阶之路】<<====
=====>>⑤【机器学习和python大牛带你入门到进阶之路】<<====
=====>>⑥【架构师大牛带你入门到进阶之路】<<=====
=====>>⑦【C++大牛带你入门到进阶之路】<<====
=====>>⑧【ios大牛带你入门到进阶之路】<<====
=====>>⑨【Web安全大牛带你入门到进阶之路】<<=====
=====>>⑩【Linux和操作系统大牛带你入门到进阶之路】<<=====

天下没有不劳而获的果实,望各位年轻的朋友,想学技术的朋友,在决心扎入技术道路的路上披荆斩棘,把书弄懂了,再去敲代码,把原理弄懂了,再去实践,将会带给你的人生,你的工作,你的未来一个美梦。

 类似资料: