初次搭建spring boot maven项目报错之Unable to find main class

首次搭建spring boot 项目时pom.xml如下
<?xml version="1.0" encoding="UTF-8"?>
<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.mycompany</groupId>
    <artifactId>SpringBoot</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>SpringBoot</name>

    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>
    
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    
    <dependencies>
        <!--spring boot-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>7.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

构建时报错信息如下

--- spring-boot-maven-plugin:1.3.1.RELEASE:repackage (default) @ SpringBoot ---
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 5.188 s
Finished at: 2017-09-05T11:25:05+08:00
Final Memory: 23M/286M
------------------------------------------------------------------------
Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.3.1.RELEASE:repackage (default) on project SpringBoot: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.3.1.RELEASE:repackage failed: Unable to find main class -> [Help 1]

repackage failed: Unable to find main class -> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.Re-run Maven using the -X switch to enable full debug logging.

其中抓取重要信息

Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.3.1.RELEASE:repackage (default) on project SpringBoot: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.3.1.RELEASE:repackage failed: Unable to find main class -> [Help 1]

提取信息为:

repackage failed: Unable to find main class -> [Help 1]

原因找到了,是因为缺少主类,修饰一下就是没有spring boot java入口配置类

于是:新建java文件就可以了:

package com.mycompany.springboot;

import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * TODO(在这里用一句话描述这个类的作用) 
 * @ClassNmae:NewClass   
 * @author zlx-雄雄
 * @date    2017-9-5 11:29:44
 * 
 */
@SpringBootApplication
public class NewClass {
    public static void main(String[] args) {
        
    }
}


我这里用的开发工具是Netbeans8.0.3,但是这个配置跟开发工具没有关系
其他开发工具可以参考:http://blog.csdn.net/Evan_Leung/article/details/52498301?locationNum=7&fps=1

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

生命无须向死而生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值