只需通过弹簧引导教程并继续执行步骤4.4.4执行$ mvn spring-boot:run
以下是错误:
$ mvn spring-boot:run
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< com.example:myproject >------------------------
[INFO] Building myproject 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:3.0.0-SNAPSHOT:run (default-cli) > test-compile @ myproject >>>
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ myproject ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory /Users/dnatochy/development/springboot/testapp1/src/main/resources
[INFO] skip non existing resourceDirectory /Users/dnatochy/development/springboot/testapp1/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.10.1:compile (default-compile) @ myproject ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /Users/dnatochy/development/springboot/testapp1/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.078 s
[INFO] Finished at: 2022-07-26T21:27:48-07:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile (default-compile) on project myproject: Fatal error compiling: invalid target release: 17 -> [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
我在Google上找到的所有类似于此错误的地方都指向maven使用的java版本的不匹配,但事实并非如此。
$ java -version
java version "1.8.0_333"
Java(TM) SE Runtime Environment (build 1.8.0_333-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.333-b02, mixed mode)
$ javac -version
javac 1.8.0_333
$ mvn -v
Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
Maven home: /Users/myuser/tools/apache-maven-3.8.6
Java version: 1.8.0_333, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_333.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "12.4", arch: "x86_64", family: "mac"
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_333.jdk/Contents/Home
发布于 2022-07-27 06:18:41
正如@1615903所指出的,我需要java 17。
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/myuser/development/springboot/testapp1/src/main/java/MyApplication.java:[1,2] cannot find symbol
symbol: class RestController
[ERROR] /Users/myuser/development/springboot/testapp1/src/main/java/MyApplication.java:[2,2] cannot find symbol
symbol: class EnableAutoConfiguration
[ERROR] /Users/myuser/development/springboot/testapp1/src/main/java/MyApplication.java:[5,10] cannot find symbol
symbol: class RequestMapping
location: class MyApplication
[ERROR] /Users/myuser/development/springboot/testapp1/src/main/java/MyApplication.java:[11,17] cannot find symbol
symbol: variable SpringApplication
将导入语句添加到MyApplication.java之后,应用程序编译并运行
import org.springframework.web.bind.annotation.RestController;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.web.bind.annotation.RequestMapping;
发布于 2022-09-26 09:22:11
您应该检查在JAVA_HOME中配置了哪个Java版本。Use:mvn -version
您应该可以从mvn
输出中看到类似的内容
$ mvn -version
Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0)
Maven home: path\apache-maven-3.8.5
Java version: 17.0.3.1, vendor: Oracle Corporation, runtime: path\Java\jdk-17.0.3.1
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
您也可以跟踪这篇文章以获得更多的解决方案。https://mkyong.com/maven/maven-error-invalid-target-release-17/
发布于 2022-10-07 17:16:40
确保Maven使用的JAVA与目标相同或更新。
mvn -version
命令。确保“运行时:”指向您的新JAVA路径https://stackoverflow.com/questions/73132312
复制相似问题