如何在生成的jar文件的清单中指定主类? [英] How do I specify a main class in the manifest of my generated jar file?
本文介绍了如何在生成的jar文件的清单中指定主类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用Eclipse Maven构建具有依赖关系的jar
但是当我执行时
i try to using Eclipse Maven to build jar with dependencies but when i execute
java -jar App.jar
得到错误:找不到主要方法
got the error : "no main method found"
我的pom.xml如下所示:
My pom.xml looks like this:
<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>
<groupId>com.maventest</groupId>
<artifactId>aproject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>aproject</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
它只是一个简单的java代码:
it's just a simple java code:
package com.maventest.aproject;
public class App {
public static void main( String[] args ) {
System.out.println( "Hello World!" );
}
}
eclipse版本:4.5.2
eclipse version: 4.5.2
任何人都可以帮我这个吗?
谢谢。
Can anyone help me with this? Thanks.
推荐答案
您可以使用maven-jar-plugin实现此目的。
You can use maven-jar-plugin for that purpose.
<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin.version}</version>
<configuration>
<archive>
<manifest>
<!-- <addClasspath>true</addClasspath> -->
<mainClass>twaren.elk.elkMaven.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
这篇关于如何在生成的jar文件的清单中指定主类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文