刚刚完成spring-boot 教程并陷入步骤 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
Run Code Online (Sandbox Code Playgroud)
我在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
Run Code Online (Sandbox Code Playgroud)
Alt*_*ter 35
您应该检查 JAVA_HOME 中配置的 Java 版本。使用:您应该从输出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"
Run Code Online (Sandbox Code Playgroud)
您也可以关注这篇文章以获取更多解决方案。 https://mkyong.com/maven/maven-error-invalid-target-release-17/
R..*_*... 13
确保 Maven 使用的 JAVA 版本与您的目标相同或更新。
mvn -version
命令。确保“runtime:”指向您的新 JAVA 路径As @1615903 pointed out I needed java 17. After installing it, I started getting compilation errors
[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
Run Code Online (Sandbox Code Playgroud)
After adding import statements to MyApplication.java, the app compiled and ran
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;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
111709 次 |
最近记录: |