Error using SonarLint in Visual Studio Code (VsCode) and Java 11

huangapple go评论72阅读模式
英文:

Error using SonarLint in Visual Studio Code (VsCode) and Java 11

问题

我在使用Visual Studio Code中的SonarLint时遇到了问题。我之前在Java 8中使用这个插件非常顺利,但大约在上周,Vscode要求最低使用Java 11版本,当我更新后(我仍然在我的项目中继续使用Java 8,根据Vscode可以使用两个版本),插件无法正常启动,出现以下错误:

[Error - 16:57:02.682] 分析失败。

[Error - 16:57:02.683] java.lang.IllegalStateException: 没有匹配 'C:\Users\MyUser.m2\repository\com\sun\java\tools\11\tools-11.jar' 的文件或目录。

我知道在Java 11中不存在tools.jar,并且我找不到替代它的jar文件或解决此问题的方法。
我正在使用SonarLint插件的最新版本1.17.0。

谢谢你的回答。

英文:

I have a problem using SonarLint in visual studio code, I’ve been using very well this plugin in java 8 but arround last week, Vscode required java 11 as minimum java version and when I updated this (I keep using java 8 for my project, according to Vscode can use two versions), the plugin couldn’t start well, this is a error:
[Error - 16:57:02.682] Analysis failed.

[Error - 16:57:02.683] java.lang.IllegalStateException: No files nor directories matching 'C:\Users\MyUser.m2\repository\com\sun\java\tools\11\tools-11.jar'

I know that tools.jar doesn’t exist in java 11 and I couldn’t find a jar to replace it or a way to solve this.
I’m using the last version of sonarLint plugin 1.17.0

Thanks for your answers.

答案1

得分: 17

要求
SonarLint语言服务器需要Java Runtime(JRE)8或11。如果您的计算机已经安装了一个合适的JRE,SonarLint应该会自动找到并使用它。

如果在通常的位置找不到合适的JRE,SonarLint将会征求您的许可来下载并管理自己的版本。

最后,您可以在VS Code设置中明确设置JRE安装路径,使用sonarlint.ls.javaHome变量。例如:

{
"sonarlint.ls.javaHome": "C:\Program Files\Java\jre-11.0.11"
}

在Windows上,反斜杠必须被转义,例如C:\Program Files\Java\jdk-11.0.11
在macOS上,此路径应包括/Contents/Home目录,例如/Library/Java/JavaVirtualMachines/jdk-11.0.11.jdk/Contents/Home

为了分析JavaScript和TypeScript,SonarLint还需要Node.js。

要启用对Java的支持,您需要安装Language support for Java VSCode扩展(版本0.56.0或更高)。

仅当与SonarQube/SonarCloud一起使用时,才能支持Apex和PL/SQL。对于Apex,您还需要Salesforce Extension Pack VSCode扩展。

英文:

Requirements
The SonarLint language server needs a Java Runtime (JRE) 8 or 11. If one is already installed on your computer, SonarLint should automatically find and use it.

If a suitable JRE cannot be found at the usual places, SonarLint will ask for your permission to download and manage its own version.

Finally, you can explicitly set the path where the JRE is installed using the sonarlint.ls.javaHome variable in VS Code settings. For instance:

{
    "sonarlint.ls.javaHome": "C:\\Program Files\\Java\\jre-11.0.11"
}

On Windows, backslashes must be escaped, e.g. C:\Program Files\Java\jdk-11.0.11
On macOS, this path should include the /Contents/Home directory, e.g /Library/Java/JavaVirtualMachines/jdk-11.0.11.jdk/Contents/Home

To analyze JavaScript and TypeScript, SonarLint will also need Node.js.

To enable the support for Java, you need the Language support for Java VSCode extension (version 0.56.0 or higher).

The support for Apex and PL/SQL is only available together with SonarQube/SonarCloud. For Apex, you'll also need the Salesforce Extension Pack VSCode extension.

答案2

得分: 2

Go to File-> Preferences -> Settings

然后搜索sonarlint以打开其设置

将您的Java目录路径复制粘贴到这里。在我的情况下,我不得不转义反斜杠。

英文:

Go to File-> Preferences -> Settings

Then search for sonarlint to bring up its settings

Copy-paste your java directory path here. In my case, I had to escape the backslashes.

Error using SonarLint in Visual Studio Code (VsCode) and Java 11

答案3

得分: 2

在回答中补充一下,如果你在Windows中使用VSCode,并且在WSL中安装了"Remote - WSL"扩展。你需要执行以下步骤:

  1. 在WSL(例如Ubuntu)中安装JDK 11。
  2. 更新位于WSL /home/$username/.vscode-server/data/Machine下的settings.json,添加属性"sonarlint.ls.javaHome"并将值设置为WSL中JDK 11的主目录路径。
英文:

Just a supplement to the answer, if you are using VSCode in Windows with WSL and installed the "Remote - WSL" extension. You need to:

  1. Install the JDK 11 in the WSL (e.g. Ubuntu)
  2. Update the settings.json under WSL /home/$username/.vscode-server/data/Machine to add the attriutte "sonarlint.ls.javaHome" and set the value to the home path of the JDK 11 in the WSL

答案4

得分: 1

I tried it, and everything works well. Could I verify somethings?

我尝试过了,一切都运行良好。我可以验证一些事情吗?

Do you set the settings.json file like this?

你是否设置了像这样的settings.json文件?

"java.home": "[Path to JDK]", // 例如:D:\workSoft\JDK11

"java.configuration.runtimes": [ // 这应该在User settings.json中设置
{
"name": "JavaSE-11",
"path": "[Path to JDK]"
},
{
"name": "JavaSE-1.8",
"path": "[Path to JDK]",
"default": true
}
]

你是否设置了类似这样的settings.json文件?

"java.home": "[JDK路径]", // 例如:D:\workSoft\JDK11

"java.configuration.runtimes": [ // 这应该在User settings.json中设置
{
"name": "JavaSE-11",
"path": "[JDK路径]"
},
{
"name": "JavaSE-1.8",
"path": "[JDK路径]",
"default": true
}
]

I tried this, and everything works well. The java extension depends on JDK11 and my project depends on JDK8. SonarLint works well too.

我尝试了这个,一切都运行良好。Java扩展依赖于JDK11,而我的项目依赖于JDK8。SonarLint也工作正常。

And you can find this in the details page of SonarLint extension:

您可以在SonarLint扩展的详细页面中找到这些信息:

The SonarLint language server needs a Java Runtime (JRE) 8 or 11. If one is already installed on your computer, SonarLint should automatically find and use it.
If a suitable JRE cannot be found at the usual places, SonarLint will ask for your permission to download and manage its own version.
Finally, you can explicitly set the path where the JRE is installed using the sonarlint.ls.javaHome variable in VS Code settings. For instance:

SonarLint语言服务器需要Java运行时(JRE)8或11。如果已经在计算机上安装了一个,SonarLint应该会自动找到并使用它。
如果在通常的位置找不到合适的JRE,SonarLint将请求您的许可来下载和管理其自己的版本。
最后,您可以在VS Code设置中使用sonarlint.ls.javaHome变量明确设置JRE安装路径。例如:

{
"sonarlint.ls.javaHome": "C:\Program Files\Java\jre1.8.0_131"
//我尝试过: "D:\workSoft\JDK8" 和 "D:\workSoft\JDK11" 都可以工作。
}

英文:

I tried it, and everything works well. Could I verify somethings?

Do you set the settings.json file like this?

"java.home": "[Path to JDK]", // For example: D:\\workSoft\\JDK11

"java.configuration.runtimes": [  // This should be setted in User settings.json
    {
      "name": "JavaSE-11",
      "path": "[Path to JDK]"
    },
    {
      "name": "JavaSE-1.8",
      "path": "[Path to JDK]",
      "default": true
    }
  ]

I tried this, and everything works well. The java extension depends on JDK11 and my project depends on JDK8. SonarLint works well too.

And you can find this in the details page of SonarLint extension:

The SonarLint language server needs a Java Runtime (JRE) 8 or 11. If one is already installed on your computer, SonarLint should automatically find and use it.
If a suitable JRE cannot be found at the usual places, SonarLint will ask for your permission to download and manage its own version.
Finally, you can explicitly set the path where the JRE is installed using the sonarlint.ls.javaHome variable in VS Code settings. For instance:

{
    "sonarlint.ls.javaHome": "C:\\Program Files\\Java\\jre1.8.0_131"
    //I tried: both of "D:\\workSoft\\JDK8" and "D:\\workSoft\\JDK11" works.
}

huangapple
  • 本文由 发表于 2020年8月6日 06:28:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/63274390.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定