无法使用m2eclipse制作可执行jar [英] Cannot make executable jar using m2eclipse

查看:115
本文介绍了无法使用m2eclipse制作可执行jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始学习如何使用m2eclipse.我要做的是制作一个非常简单的程序(Hello,World)并将其转换为可执行jar. Java代码本身是:

I have just started learning how to use m2eclipse. What I am trying to do is make a very simple program (Hello, World) and turn it into an executable jar. The java code itself is:

公共课说{

/**
 * @param args
 */
public static void main(String[] args) {
    System.out.println("Meow!");
}

}

作为Java应用程序可以很好地运行.然后,我尝试使用Maven来构建程序,但确实如此,但是当我尝试运行.jar时,它告诉我无法从...加载Main-Class属性".这是我启动项目时m2eclipse生成的.pom:

which runs fine as a Java application. I then try to use Maven to build the program, which it does, but then when I try to run the .jar it tells me "Failed to load Main-Class attribute from ...". This is the .pom that m2eclipse generated when I started the project:

<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>org.felines</groupId>
<artifactId>tabbies</artifactId>
<version>0.0</version>
<dependencies>
<dependency>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-jar-plugin</artifactId>
  <version>2.3.1</version>
  <type>maven-plugin</type>
  <scope>compile</scope>
</dependency>
</dependencies>
</project>

我尝试修改.pom,如下所示:

I have tried modifying the .pom, like so:

<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>org.felines</groupId>
<artifactId>tabbies</artifactId>
<version>0.0</version>
<build>
<plugins>
    <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.3.1</version>
        <configuration>
        <archive>
        <manifest>
             <mainClass>org.felines.Speak</mainClass>
             <packageName>org.felines</packageName>
        </manifest>
            <manifestEntries>
                <mode>development</mode>
                <url>${pom.url}</url>
        </manifestEntries>
        </archive>
        </configuration>
    </plugin>
</plugins>
</build>
</project>

现在它说:找不到主类:org.felines.Speak.程序将退出."有任何想法吗? :(

Now it says "Could not find the main class: org.felines.Speak. Program will exit." Any ideas? :(

谢谢您的时间!

推荐答案

在pom.xml中,您声明主类应该为org.felines.Speak.但是该类实际上位于默认程序包中,这意味着没有程序包定义.因此,要么在类实现中将包设置为org.felines,要么将pom.xml中的mainClass条目单独更改为Speak.然后应该可以找到启动jar的必要信息.

In your pom.xml you state that the main class should be org.felines.Speak. But the class is actually in the default package, meaning no package definition. So either set the package to org.felines in the class implementation or change your mainClass entry in the pom.xml to Speak alone. Then the necessary information to start the jar should be available.

这篇关于无法使用m2eclipse制作可执行jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆