网上搜了一圈, 都说这是jdk 9的参数, 我用 jdk 8就要报错, 实际上解决方法很简单
报错如下:
C:\Users\HW\.jabba\jdk\default\bin\java.exe -Xmx700m -Djava.awt.headless=true "-Djna.boot.library.path=C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2024.1/lib/jna/amd64" -Djna.nosys=true -Djna.noclasspath=true --add-opens jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED -Dexternal.project.config=C:\Users\HW\AppData\Local\JetBrains\IdeaIC2024.1\projects\yuguan-backend.8de06894\external_build_system -Dcompile.parallel=false -Drebuild.on.dependency.change=true -Didea.IntToIntBtree.page.size=32768 -Djdt.compiler.useSingleThread=true -Daether.connector.resumeDownloads=false -Dio.netty.initialSeedUniquifier=2150057486439607630 -Dfile.encoding=GBK -Duser.language=zh -Duser.country=CN -Didea.paths.selector=IdeaIC2024.1 "-Didea.home.path=C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2024.1" -Didea.config.path=C:/Users/HW/AppData/Roaming/JetBrains/IdeaIC2024.1 -Didea.plugins.path=C:/Users/HW/AppData/Roaming/JetBrains/IdeaIC2024.1/plugins -Djps.log.dir=C:/Users/HW/AppData/Local/JetBrains/IdeaIC2024.1/log/build-log "-Djps.fallback.jdk.home=C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2024.1/jbr" -Djps.fallback.jdk.version=17.0.10 -Dio.netty.noUnsafe=true -Djava.io.tmpdir=C:/Users/HW/AppData/Local/JetBrains/IdeaIC2024.1/compile-server/yuguan-backend_acfae7b0/_temp_ -Djps.backward.ref.index.builder=true "-Djps.kotlin.home=C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2024.1\plugins\Kotlin\kotlinc" -Dkotlin.incremental.compilation=true -Dkotlin.incremental.compilation.js=true -Dkotlin.daemon.enabled -Dkotlin.daemon.client.alive.path=\"C:\Users\HW\AppData\Local\Temp\kotlin-idea-6093052720390690581-is-running\" -Dide.propagate.context=false -classpath "C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2024.1/plugins/java/lib/jps-launcher.jar" org.jetbrains.jps.cmdline.Launcher "C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2024.1/plugins/java/lib/jps-builders.jar;C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2024.1/plugins/java/lib/jps-builders-6.jar;C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2024.1/plugins/java/lib/jps-javac-extension.jar;C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2024.1/lib/util-8.jar;C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2024.1/lib/util_rt.jar;C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2024.1/lib/platform-loader.jar;C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2024.1/lib/annotations.jar;C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2024.1/lib/trove.jar;C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2024.1/plugins/java/lib/jetbrains.kotlinx.metadata.jvm.jar;C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2024.1/lib/protobuf.jar;C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2024.1/lib/jps-model.jar;C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2024.1/plugins/java/lib/javac2.jar;C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2024.1/lib/forms_rt.jar;C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2024.1/lib/util.jar;C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2024.1/plugins/java/lib/aether-dependency-resolver.jar;C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2024.1/plugins/java/lib/maven-resolver-connector-basic.jar;C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2024.1/plugins/java/lib/maven-resolver-transport-file.jar;C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2024.1/plugins/java/lib/maven-resolver-transport-http.jar;C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2024.1/lib/idea_rt.jar;C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2024.1/plugins/Kotlin/lib/jps/kotlin-jps-plugin.jar;C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2024.1/lib/util-8.jar;C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2024.1/plugins/eclipse/lib/eclipse-jps.jar;C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2024.1/plugins/eclipse/lib/eclipse-common.jar;C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2024.1/plugins/platform-langInjection/lib/java-langInjection-jps.jar;C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2024.1/plugins/Groovy/lib/groovy-jps.jar;C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2024.1/plugins/Groovy/lib/groovy-constants-rt.jar;C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2024.1/plugins/javaFX/lib/javaFX-jps.jar;C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2024.1/plugins/javaFX/lib/javaFX-common.jar;C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2024.1/plugins/uiDesigner/lib/jps/java-guiForms-jps.jar;C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2024.1/plugins/maven/lib/maven-jps.jar;C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 2024.1/plugins/gradle-java/lib/gradle-jps.jar" org.jetbrains.jps.cmdline.BuildMain 127.0.0.1 9261 1c7649b0-ceb4-48ae-9c3c-36228e7f424d C:/Users/HW/AppData/Local/JetBrains/IdeaIC2024.1/compile-server
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Unrecognized option: --add-opens
解决办法:
不用怀疑idea的问题, 要检查你的jdk是否一致
File->Project Structure 我把多余的sdks全部删除掉, 换成命令行一致的环境变量, 然后重新设置一下sdk, 另外记得全部删除掉, 重新添加, 然后就比较爽快啦
将project , modules重新设置成当前的sdk