maven - package a jar with main class

run the class

mvn clean compile exec:java -Dexec.args="s1 s2 s3'" -Dexec.mainClass="foo.bar.FBI"

package the jar

mvn package

pom

<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>
	<name>BarPost</name>
	<groupId>com.foo</groupId>
	<artifactId>jPoster</artifactId>
	<version>1.0.0-SNAPSHOT</version>
	<packaging>jar</packaging>
	<!-- More Project Information -->
	<repositories>
		<repository>
			***
		</repository>
		<repository>
	</repositories>

	<dependencyManagement>
		<dependencies>
			<!-- Testing -->
			<dependency>
				<groupId>junit</groupId>
				<artifactId>junit</artifactId>
				<scope>test</scope>
				<version>4.11</version>
			</dependency>
		</dependencies>
	</dependencyManagement>
	<build>
		<pluginManagement>
			<plugins>
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-site-plugin</artifactId>
					<version>3.3</version>
				</plugin>
				<plugin>
					<artifactId>maven-compiler-plugin</artifactId>
					<version>2.5.1</version>
					<configuration>
						<source>1.6</source>
						<target>1.6</target>
					</configuration>
				</plugin>
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-jar-plugin</artifactId>
					<configuration>
						<archive>
							<manifest>
								<mainClass>com.foo.BAR</mainClass>
							</manifest>
						</archive>
					</configuration>
				</plugin>
			</plugins>
		</pluginManagement>
	</build>
</project>


发布了386 篇原创文章 · 获赞 19 · 访问量 82万+

猜你喜欢

转载自blog.csdn.net/watson243671/article/details/22194627
今日推荐