【问题标题】:Cannot make executable jar using m2eclipse无法使用 m2eclipse 制作可执行的 jar
【发布时间】:2011-05-19 14:42:40
【问题描述】:

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

公开课说{

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

}

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

<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,如下所示:

<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。程序将退出。”有任何想法吗? :(

感谢您的宝贵时间!

【问题讨论】:

  • Speak 课中的 package 语句是什么?
  • 我认为对于这样一个简单的程序,我可以使用默认包,因此没有包语句。那是我做错了吗?

标签: maven manifest m2eclipse


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-03
    • 1970-01-01
    相关资源
    最近更新 更多