【发布时间】:2020-04-29 16:42:51
【问题描述】:
我对 Java 技术非常陌生(通常使用 NodeJs 和 PHP,但需要使用 Spring Boot)。我只想在 Spring MVC 上运行“Hello World”。但是我已经用了一天了。我不知道为什么仅仅初始化一个项目就超级难。
我从https://start.spring.io/ 构建了一个项目
Project: Marven, LanguageL Java, Spring Boot:2.2.6, Packing: Java, Java: 11
Dependencies: Spring Web WEB, Thymeleaf and Spring Boot DevTools.
我的 mvn 版本,
Maven home: /usr/local/Cellar/maven/3.6.0/libexec
Java version: 11.0.7, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-11.0.7.jdk/Contents/Home
Default locale: en_TH, platform encoding: UTF-8
OS name: "mac os x", version: "10.14.5", arch: "x86_64", family: "mac"
我的 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.myproject</groupId>
<artifactId>front-end-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>front-end-server</name>
<description>Front End Server</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
当我尝试运行时,它总是返回错误,
[INFO] Total time: 0.604 s
[INFO] Finished at: 2020-04-29T23:22:55+07:00
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "pom.xml" could not be activated because it does not exist.
[ERROR] Unknown lifecycle phase "mvn". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [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/LifecyclePhaseNotFoundException
我也关注了http://cwiki.apache.org/confluence/display/MAVEN/LifecyclePhaseNotFoundException。但它不起作用。
我也试过https://crunchify.com/mavenmvn-clean-install-update-project-and-project-clean-options-in-eclipse-ide-to-fix-any-dependency-issue/的解决方案 它没有再次醒来。
此外,我还使用 Spring Tool Suite 4 创建了一个新项目(希望得到不同的结果)。它也不能正常工作。
我通常需要不到 30 分钟的时间来为新事物开启一个“hello world”。但是对于 Spring boot,已经花了我一整天的时间。
请帮忙..
【问题讨论】:
-
您是如何运行构建或通过命令提示符运行的?
-
你说“运行它”,但没有具体说明如何。
-
您可能使用了错误的命令来运行 Maven。你在用什么命令?尝试简单地使用
mvn clean install进行编译,而不使用-P之类的任何选项。要运行应用程序,请尝试mvn spring-boot:run。
标签: java spring spring-boot maven