Maven错误:无法找到或加载主类 [英] Maven Error: Could not find or load main class

查看:1018
本文介绍了Maven错误:无法找到或加载主类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Java Maven程序,我不知道输入什么作为< mainClass> 。我已经根据众多尝试了各种各样的事情。 stackoverflow问题,但他们没有解决错误。

I'm using a Java Maven program and I don't know what to enter as the <mainClass>. I've tried all kinds of things based off of numerous stackoverflow questions, but they are not solving the error.

每次都说:

Maven Error: Could not find or load main class ...

我在 pom中写了这个.xml (减去 ???

  <build>
  ...
  <plugins>
  ...
    <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.5.3</version>
        <configuration>
            <descriptors>
                <descriptor>src/main/assembly/jar-with-dependencies.xml</descriptor>
            </descriptors>
            <archive>
                <manifest>
                    <mainClass> ??? </mainClass>
                </manifest>
            </archive>
        </configuration>
        <executions>
            <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
            </execution>
        </executions>
    </plugin>
  ...
  </plugins>
  ...
  </build>

如何解决这些错误?

推荐答案

除非你因为设置mainClass而不需要'maven-assembly-plugin',否则你可以使用' maven-jar-plugin '插件。

Unless you need the 'maven-assembly-plugin' for reasons other than setting the mainClass, you could use the 'maven-jar-plugin' plugin.

     <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <archive>
                    <index>true</index>
                    <manifest>
                        <mainClass>your.package.yourprogram.YourMainClass</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
     </plugins>

您可以在 ATLauncher

'mainClass'元素应该设置为您拥有程序入口点的类,例如:

The 'mainClass' element should be set to the class that you have the entry point to your program in eg:

package your.package.yourprogram;

public class YourMainClass {

    public static void main(String[] args) {
        System.out.println("Hello World");
    }
}

这篇关于Maven错误:无法找到或加载主类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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