使用maven-jar-plugin 插件,将一个有两个入口的java工程打包为两个jar,每个jar有自己的main入口

5 篇文章 0 订阅

情景

我有一个工程,由于一些原因,里面有两个入口(两个类都有main()String[] args)。而且我需要将这两个打包为两个独立的jar,并且每个jar中的配置文件只打包自己想要的。

比如下面的工程,划红线的两个类有各自的main函数,执行各自的逻辑:

 附加需求:

1. 每个jar不需要bin和xmls的所有文件

2. logback文件各自使用各自的,也是就不要包含对方的logback.xml

实现

使用 maven-jar-plugin 插件实现。

	<build>
		<finalName>myApp</finalName>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-jar-plugin</artifactId>
				<executions>
					<execution>
						<id>command-jar</id><!-- 包名,打出的jar包会被 finalName+id的方式命名-->
						<goals>
							<goal>jar</goal>
						</goals>
						<phase>package</phase>
						<configuration>
							<excludes><!-- 排除文件在这里配置 -->
								<exclude>/logback-recall.xml</exclude>
								<exclude>/*bin/**</exclude><!--/*bin无效,还是会保留bin以及下面的所有;/*bin/**会把bin以及下面的所有都排除;/bin/*只会排除bin下面的-->
								<exclude>/*xmls/**</exclude>
								<exclude>/assembly.xml</exclude>
							</excludes>
							<archive>
								<manifest>
									<addClasspath>true</addClasspath>
									<classpathPrefix>lib/</classpathPrefix>
									<mainClass>com.jfqqqq.command.CommandApp</mainClass>
								</manifest>
							</archive>
							<classifier>command-jar</classifier>
					</configuration>
					</execution>
					<execution>
						<id>recaller-jar</id>
						<goals>
							<goal>jar</goal>
						</goals>
						<phase>package</phase>
						<configuration>
							<excludes>
								<exclude>/logback-command.xml</exclude>
								<exclude>/*bin/**</exclude><!--/*bin无效,还是会保留bin以及下面的所有;/*bin/**会把bin以及下面的所有都排除;/bin/*只会排除bin下面的-->
								<exclude>/*xmls/**</exclude>
								<exclude>/assembly.xml</exclude>
							</excludes>
							<classifier>recaller-jar</classifier>
							<archive>
								<manifest>
									<addClasspath>true</addClasspath>
									<classpathPrefix>lib/</classpathPrefix>
									<mainClass>com.jfqqqq.recall.RecallerApp</mainClass>
								</manifest>
							</archive>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>

效果

 解压后(以myApp-command-jar.jar为例):

 完成

预告

接着本文,后边会在写一个将两个jar打包到一个公共的zip包下的demo。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值