maven里pom文件指定jar和依赖打包输出路径

java 文章 2022-07-28 11:14 0 全屏看文
<plugins>
	<plugin>
		<artifactId>maven-compiler-plugin</artifactId>
		<configuration>
			<source>1.8</source>
			<target>1.8</target>
		</configuration>
	</plugin>
	<plugin>
		<groupId>org.apache.maven.plugins</groupId>
		<artifactId>maven-jar-plugin</artifactId>
		<configuration>
			<outputDirectory>/mnt/jars/btoolsm</outputDirectory>
			<!-- MainClass in mainfest make a executable jar -->
			<archive> 
				<manifest>
					<mainClass>com.btools.DemoMain</mainClass>
				</manifest>
			</archive>
		</configuration>
	</plugin>
	<plugin>
		<groupId>org.apache.maven.plugins</groupId>
		<artifactId>maven-dependency-plugin</artifactId>
		<executions>
			<execution>
				<id>copy</id>
				<phase>package</phase>
				<goals>
					<goal>copy-dependencies</goal>
				</goals>
				<configuration>
					<outputDirectory>/mnt/jars/btoolsm/lib</outputDirectory>
				</configuration>
			</execution>
		</executions>
	</plugin>

</plugins>

git install的时候 会分别吧jar和依赖发布到指定的地方。

编译成功后可以运行命令启动项目:

java -Djava.ext.dirs=/mnt/jars/btoolsm/lib -jar  /mnt/jars/btoolsm/btoolsm-0.0.1-SNAPSHOT.jar


-EOF-