Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Maven生成失败-缺少主类_Java_Spring_Maven_Spring Boot - Fatal编程技术网

Java Maven生成失败-缺少主类

Java Maven生成失败-缺少主类,java,spring,maven,spring-boot,Java,Spring,Maven,Spring Boot,我正在尝试使用Maven开始使用Spring引导应用程序。我已经完成了以下教程: 我的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.o

我正在尝试使用Maven开始使用Spring引导应用程序。我已经完成了以下教程:

我的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.example</groupId>
<artifactId>myproject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.0.BUILD-SNAPSHOT</version>
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>
<!-- Additional lines to be added here... -->

<!-- (you don't need this if you are using a .RELEASE version) -->
<repositories>
    <repository>
        <id>spring-snapshots</id>
        <url>http://repo.spring.io/snapshot</url>
        <snapshots><enabled>true</enabled></snapshots>
    </repository>
    <repository>
        <id>spring-milestones</id>
        <url>http://repo.spring.io/milestone</url>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>spring-snapshots</id>
        <url>http://repo.spring.io/snapshot</url>
    </pluginRepository>
    <pluginRepository>
        <id>spring-milestones</id>
        <url>http://repo.spring.io/milestone</url>
    </pluginRepository>
</pluginRepositories>
如果我用mvn spring boot:run-in-cmd运行它,我会得到一个构建失败,注意到它找不到合适的主类

堆栈跟踪:

[INFO] BUILD FAILURE
[INFO]      ------------------------------------------------------------------------
[INFO] Total time: 2.206 s
[INFO] Finished at: 2017-07-21T12:33:18+02:00
[INFO] Final Memory: 21M/227M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-     maven-plugin:2.0.0.BUILD-SNAPSHOT:run (default-cli) on project myproject:   Unable to find a suitable main class, please add a 'mainClass' property ->   [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions,   please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Maven希望文件位于特定位置: 如果java文件位于Test\src\main\java中,则pom文件应位于Test中,而不是Test\bin

只要用相同的代码运行它,它就可以很好地构建

您可以在此处阅读有关maven中文件位置的更多信息:
您的
示例
类是有效的Spring Boot主类。

问题在于:

Pom.xml在Test\bin中

您的pom.xml未在正确的位置声明。

默认情况下,Maven希望
src\main\java
文件夹位于定义pom.xml的同一级别。

因此,通过这种布局,Maven尝试在中查找您的类

Test\bin\src\main\java
但你们的课程在这里:

我的项目文件夹如下所示:Test\src\main\java


只需将pom.xml移到Test文件夹的根目录下。

添加stacktrace pleaseJava文件位于Test\src\main\javaThank you’感谢您的帮助谢谢您的帮助
Test\bin\src\main\java