maven搭建底层工具包(一)

时间:2024-04-14 09:30:33

maven搭建底层工具包(一)

环境:eclipse,maven,jdk1.7
目的:搭建工具jar包

1、新建项目

maven搭建底层工具包(一)
maven搭建底层工具包(一)
生成默认的pom.xml,version可以改成自己的版本号
maven搭建底层工具包(一)

2、构件项目

a:如果maven install的时候报错,在pom.xml中加入如下属性,jdk版本改为自己的。

<properties>
	<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	<java.version>1.7</java.version>
</properties>

b:打包Jar的时候带上Maven依赖包

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-assembly-plugin</artifactId>
				<version>2.4.1</version>
				<configuration>
					<!-- get all project dependencies -->
					<descriptorRefs>
						<descriptorRef>jar-with-dependencies</descriptorRef>
					</descriptorRefs>
					<!-- MainClass in mainfest make a executable jar -->
					<archive>
						<manifest>
							<mainClass>util.Microseer</mainClass>
						</manifest>
					</archive>
 
				</configuration>
				<executions>
					<execution>
						<id>make-assembly</id>
						<!-- bind to the packaging phase -->
						<phase>package</phase>
						<goals>
							<goal>single</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>

install成功后,得到两个jar包:xxx-1.0.0-jar-with-dependencies.jar和xxx-1.0.0.jar。xxx-1.0.0-jar-with-dependencies.jar就是已经把依赖包都打包好的Jar包