初次搭建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
还没有评论,来说两句吧...