maven默认的install命令所打的jar运行时是找不到可执行主类的,要将maven工程打成可执行jar包需要加maven插件
在maven工程的pom.xml中添加插件,代码如下
<dependencies>
<!-- 一系列的以来jar -->
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<!-- 插件-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<!--###########指定要执行的主类############ -->
<mainClass>com.cetc.di.hellocetc.SayHello</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
<classesDirectory>
</classesDirectory>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
java类
package com.cetc.di.hellocetc;
/**
* Created by mis on 2017/2/16.
*/
public class SayHello {
public static void main(String[] args) {
System.out.println("Hello ~");
}
}
在Terminal下执行命令 mvn install
2017-02-16_171620.png获取jar
2017-02-16_171720.png执行jar
2017-02-16_171756.png
网友评论