Maven错误:无法找到或加载主类MyProject.jar

时间:2019-08-20 23:14:31

标签: java maven spring-boot

我有一个Spring Boot应用程序,试图从Mac上的命令行运行,但出现以下错误:

Error: Could not find or load main class MyProject.jar

这是我的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/maven-v4_0_0.xsd">


    <modelVersion>4.0.0</modelVersion>
    <groupId>com.myproject.abc</groupId>
    <artifactId>MyProject</artifactId>
    <packaging>jar</packaging>
    <version>1.0.0</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.3.RELEASE</version>
    </parent>

    <properties>
        <start-class>com.myproject.abc.MyMain</start-class>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
        </dependency>

        <dependency>
            <groupId>com.google.collections</groupId>
            <artifactId>google-collections</artifactId>
            <version>1.0</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>target/MyProject-1.0.0.lib</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <includeSystemScope>true</includeSystemScope>
                    <archive>
                        <manifest>
                            <mainClass>com.myproject.abc.MyMain</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

        </plugins>
    </build>


</project>

我已经在线推荐了各种帖子,并且从pom.xml上方可以看到它们,尝试添加<start-class>spring-boot-maven-plugin,但是没有任何效果。

在链接Maven error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher之后的进一步搜索中,我从M2_HOME中删除了.bash_profile,如下图所示

export M2_HOME=/Users/myuser/Downloads/apache-maven-3.5.4
export PATH=$PATH:$M2_HOME/bin

然后我使用brew安装了maven->删除了.m2文件夹->运行mvn clean install->运行java MyProject.jar

仍然面临同样的问题。有什么想法吗?

0 个答案:

没有答案