Maven打包jar,連同其依賴的本地jar一起打包

1、項目所依賴的jar是沒有中心倉庫,比如阿里私服也沒有,這樣的jar有2中處理方式:

1)自己搭建nexus私服,並把該jar同步上去

2)在項目pom.xml配置:

<dependency>
    <groupId>com.nz</groupId>
    <artifactId>dubbo-api</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/lib/dubbo-api-1.0.jar</systemPath>
    <!-- 本地沒有私服,要配置systemPath,並在下面的plugin指定manifestEntries -->
</dependency>

2、maven打包項目成jar時,要配置plugins


<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>2.10</version>
    <executions>
        <execution>
            <id>copy-dependencies</id>
            <phase>package</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.directory}/lib</outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>
<!-- jar打包相關插件 -->
<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-jar-plugin</artifactId>
	<version>2.4</version>
	<configuration>
		<archive>
			<manifest>
				<addClasspath>true</addClasspath>
				<classpathPrefix>lib/</classpathPrefix>
				<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
				<mainClass>org.dubbo.server.App</mainClass>
			</manifest>
			<!-- 添加classpath缺少的內容-->
			<manifestEntries>
				<Class-Path>lib/dubbo-api-1.0.jar</Class-Path>
			</manifestEntries>
		</archive>
	</configuration>
</plugin>

3、這樣打包的jar的META-INF/MANIFEST.MF文件有兩個注意點:

Class-Path:其依賴的所有jar

Main-Class:java運行的主程序

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章