VS Code无法识别我的java项目。该项目是此处找到的minecraft mod的模板代码。我已经安装了插件
我还收到一个与gradle相关的错误。
Could not run phased build action using connection to Gradle distribution 'https://services.gradle.org/distributions/gradle-7.0.2-bin.zip'.
java.io.StreamCorruptedException: invalid type code: 00
invalid type code: 00
这是我的settings. json文件
{
"files.exclude": {
"**/.classpath": true,
"**/.project": true,
"**/.settings": true,
"**/.factorypath": true
},
"editor.suggestSelection": "first",
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
"java.configuration.updateBuildConfiguration": "interactive",
"java.home": "/usr/lib/jvm/java-16-openjdk-amd64",
"java.configuration.runtimes": [
{
"name": "JavaSE-1.8",
"path": "/usr/lib/jvm/java-8-openjdk-amd64",
"default": true
},
]
}
我的Java文件没有代码完成。在它工作之前,在Visual Studio的右下角,它显示了我正在使用的java版本,但现在它只是说Java。我假设这是因为gradle有问题,因此无法找出我的java版本。谢谢你的时间。
更新:这似乎工作,给我自动完成,但我仍然得到一个gradle相关的错误提到上面。
{
"files.exclude": {
"**/.classpath": true,
"**/.project": true,
"**/.settings": true,
"**/.factorypath": true
},
"editor.suggestSelection": "first",
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
"java.configuration.updateBuildConfiguration": "interactive",
"java.home": "/usr/lib/jvm/java-16-openjdk-amd64",
"java.configuration.runtimes": [
{
"name": "JavaSE-1.8",
"path": "/usr/lib/jvm/java-8-openjdk-amd64",
"default": true
},
{
"name": "JavaSE-16",
"path": "/usr/lib/jvm/java-16-openjdk-amd64",
},
]
}
在命令面板上运行Java:清洁Java语言服务器工作区
. project
,这样的设置文件。/settings/…files
对于任何和我遇到同样问题的人,确保你的settings. json文件看起来和我的相似,包括java1.8运行配置和java11运行配置,与指定为主路径的配置相同。这应该可以修复java语言级别。你可以忽略gradle错误,但你必须使用gradle runClient而不是vscode提供的运行配置。快乐改装:D
最后,即使我使用jenv来管理MacO上的版本(这会更改${JAVA_HOME}的路径,如下所示 /Users/userName/.jenv/versions/system),我也必须声明路径如下所示,因为. jenv权限被拒绝:
注意:
"path": /Contents/Home是必需的
"name":不能是any,它必须是一个有效的javaname
"java.jdt.ls.java. home":是已弃用的"java.home"的新键
"[java]": {
"editor.defaultFormatter": "redhat.java"
},
"java.format.enabled": true,
"java.format.settings.url": "https://raw.githubusercontent.com/google/styleguide/gh-pages/eclipse-java-google-style.xml",
"java.format.settings.profile": "GoogleStyle",
"java.format.onType.enabled": true,
"java.foldingRange.enabled": true,
"files.associations": {
"*.java": "java"
},
"java.configuration.updateBuildConfiguration": "interactive",
"java.jdt.ls.java.home": "/Library/Java/JavaVirtualMachines/openjdk.jdk/Contents/Home",
"java.configuration.runtimes": [
{
"name": "JavaSE-19",
"path": "/Library/Java/JavaVirtualMachines/openjdk.jdk/Contents/Home",
"default": true
},
{
"name": "JavaSE-17",
"path": "/Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home"
},
{
"name": "JavaSE-11",
"path": "/Library/Java/JavaVirtualMachines/jdk-11.0.14.jdk/Contents/Home"
},
{
"name": "JavaSE-1.8",
"path": "/Library/Java/JavaVirtualMachines/jdk1.8.0_321.jdk/Contents/Home/"
}
]