Maven(Eclipse插件和mvn)不包括带有pom.xml设置的主类 [英] Maven (Eclipse plugin and mvn) not including main class with pom.xml setup

查看:247
本文介绍了Maven(Eclipse插件和mvn)不包括带有pom.xml设置的主类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去几个小时我一直试图解决这个问题而且我无处可去。我刚刚安装了Maven for Eclipse插件(M2E,我认为)以及maven,mvn。我创建了一个非常简单的Hello World项目,并尝试使用以下命令运行构建的jar:
java -jar pimidi-0.0.1-SNAPSHOT.jar

I've been trying to work this out for the last few hours and I've got nowhere. I've just installed the Maven for Eclipse plugin (M2E, I think) and also the maven too, mvn. I've created a very simple Hello World project and am trying to get the built jar to run on using: java -jar pimidi-0.0.1-SNAPSHOT.jar

无论我尝试什么,我总是得到同样的错误:
没有主清单属性,在target / pimidi-0.0.1-SNAPSHOT.jar

Regardless of what I try, I always get the same error: no main manifest attribute, in target/pimidi-0.0.1-SNAPSHOT.jar

这是我的pom.xml:

Here is my pom.xml:

<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.dan</groupId>
    <artifactId>pimidi</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>pimidi</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>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-eclipse-plugin</artifactId>
            <configuration>
                <wtpversion>1.5</wtpversion>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.dan.pimidi.App</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>

我在POM的清单节点(类路径,清单位置)中尝试了无数不同的选项,不同的插件(汇编,编译等)无济于事。在Eclipse中查看有效的POM时,我可以看到maven-jar-plugin已经包含在更高级别的POM中,省略了对项目POM的任何更改。

I've tried countless different options within the manifest nodes of the POM (classpath, manifest location), different plugins (assembly, compile, etc) to no avail. On looking at the effective POM in Eclipse, I can see that maven-jar-plugin is already included from a higher-level POM an any changes to the project POM are omitted.

有没有人对如何使这个工作有任何想法?如果这个问题缺乏细节,我会道歉 - 我今晚的精神力已经过期了。任何帮助将不胜感激!

Does anyone have any ideas about how to get this working? Apologies if this question lacks detail - I have expired my mental power for this evening. Any assistance would be greatly appreciated!

推荐答案

在遵循了许多建议后,我决定删除我的项目(这只是一个mvn archetype),卸载eclipse(删除m2e插件)和〜/ .m2文件夹。然后我从命令行做了所有事情:

After following numerous pieces of advice, I decided to delete my project (which was only a mvn archetype), uninstall eclipse (to remove the m2e plugin) along with my ~/.m2 folder. I then did everything from the command line:

mvn archetype:generate -DgroupId=com.dan.pimidi -DartifactId=pimidi -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

将此添加到我的pom.xml:

Added this to my pom.xml:

<build>
        <plugins>
                <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-jar-plugin</artifactId>
                        <configuration>
                                <archive>
                                        <manifest>
                                                <mainClass>com.dan.pimidi.App</mainClass>
                                        </manifest>
                                </archive>
                        </configuration>
                </plugin>
        </plugins>
</build>

然后快速:

mvn clean package

并且a:

java -jar target/nameofjar.jar

解决了我的问题!

这篇关于Maven(Eclipse插件和mvn)不包括带有pom.xml设置的主类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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