如何使用WSL2正确设置IntelliJ [英] How to correctly set up IntelliJ with WSL2

查看:18
本文介绍了如何使用WSL2正确设置IntelliJ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法运行在WSL2下创建的项目。我收到了这个错误。有谁知道是什么原因造成的吗?

Abnormal build process termination: 
C:WINDOWSsystem32wsl.exe --distribution Ubuntu-20.04 --exec /bin/sh -c "cd /home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server && /usr/lib/jvm/java-11-openjdk-amd64/bin/java -Xmx700m -Djava.awt.headless=true -Djdt.compiler.useSingleThread=true -Dpreload.project.path=/home/jakub/test -Dpreload.config.path=/mnt/c/Users/Z004506P/AppData/Roaming/JetBrains/IntelliJIdea2021.1/options -Dcompile.parallel=false -Drebuild.on.dependency.change=true -Dio.netty.initialSeedUniquifier=-636684381209623859 -Djps.in.wsl=true -Dfile.encoding=windows-1252 -Duser.language=en -Duser.country=US -Didea.paths.selector=IntelliJIdea2021.1 '-Didea.home.path=/mnt/c/Program Files/JetBrains/IntelliJ IDEA 2021.1' -Didea.config.path=/mnt/c/Users/Z004506P/AppData/Roaming/JetBrains/IntelliJIdea2021.1 -Didea.plugins.path=/mnt/c/Users/Z004506P/AppData/Roaming/JetBrains/IntelliJIdea2021.1/plugins -Djps.log.dir=/mnt/c/Users/Z004506P/AppData/Local/JetBrains/IntelliJIdea2021.1/log/build-log '-Djps.fallback.jdk.home=/mnt/c/Program Files/JetBrains/IntelliJ IDEA 2021.1/jbr' -Djps.fallback.jdk.version=11.0.10 -Dio.netty.noUnsafe=true '-Djava.io.tmpdir=//wsl$/Ubuntu-20.04/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/test_77f155f7/_temp_' -Djps.backward.ref.index.builder=true -Dtmh.instrument.annotations=true -Dkotlin.incremental.compilation=true -Dkotlin.incremental.compilation.js=true -Dkotlin.daemon.enabled '-Dkotlin.daemon.client.alive.path="C:Users004506PAppDataLocalTempkotlin-idea-13948257364742160812-is-running"' -classpath /home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/jps-launcher.jar org.jetbrains.jps.cmdline.Launcher '/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/netty-buffer.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/nanoxml-2.2.3.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/maven-resolver-transport-file-1.3.3.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/jna-platform.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/oro-2.0.8.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/slf4j.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/log4j.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/lz4-java-1.7.1.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/jna.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/maven-resolver-provider.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/annotations.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/resources_en.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/commons-lang3-3.10.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/util.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/maven-resolver-connector-basic-1.3.3.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/jps-builders-6.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/asm-all-9.1.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/forms_rt.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/guava.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/jps-builders.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/zip-signer.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/jdom.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/intellij-deps-fastutil-8.5.2-6.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/plexus-utils-3.3.0.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/javac2.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/qdox-2.0.0.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/commons-logging-1.2.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/trove4j.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/forms-1.1-preview.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/jps-javac-extension-1.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/aether-dependency-resolver.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/http-client.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/maven-resolver-transport-http-1.3.3.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/idea_rt.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/netty-codec-http.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/jps-model.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/gson-2.8.6.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/kotlin-stdlib-jdk8.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/platform-api.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/jasper-v2-rt.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/ant-jps.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/java-guiForms-jps.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/eclipse-jps.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/eclipse-common.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/java-langInjection-jps.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/groovy-jps.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/groovy-constants-rt.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/maven-jps.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/aspectj-jps.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/gradle-jps.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/devkit-jps.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/javaFX-jps.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/javaFX-common.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/javaee-jps.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/kotlin-jps-plugin.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/kotlin-stdlib.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/kotlin-stdlib-jdk7.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/kotlin-stdlib-jdk8.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/kotlin-reflect.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/kotlin-plugin.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/kotlin-jps-common.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/kotlin-common.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/javaee-jpa-jps.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/javaee-appServers-websphere-jps.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/javaee-appServers-weblogic-jps.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/groovy-grails-jps.jar:/home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/groovy-grails-compilerPatch.jar' org.jetbrains.jps.cmdline.BuildMain 192.168.203.193 57615 867865da-6270-418c-bb35-8dcdf1591467 /home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server"
Build process started. Classpath: /home/jakub/.cache/JetBrains/IntelliJIdea2021.1/compile-server/jps-IU-211.6693.111/jps-launcher.jar
Error connecting to 192.168.203.193:57615; reason: connection timed out: /192.168.203.193:57615
io.netty.channel.ConnectTimeoutException: connection timed out: /192.168.203.193:57615
    at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe$1.run(AbstractNioChannel.java:261)
    at io.netty.util.concurrent.PromiseTask.runTask(PromiseTask.java:98)
    at io.netty.util.concurrent.ScheduledFutureTask.run(ScheduledFutureTask.java:170)
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)   at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    at java.base/java.lang.Thread.run(Thread.java:834)
Exiting.

id="official-instructions-wrong-or-out-of-date-3dv3">Official说明:错误还是过时?

推荐答案

JetBrainshttps://www.jetbrains.com/help/idea/how-to-use-wsl-development-environment-in-product.html#debugging_system_settings关于配置Windows防火墙的官方说明分为两部分

(Official)第1步:允许来自ws1的通信(这是正确的)

上述链接的第一步是添加新的入站规则,以允许来自WSL的所有流量(以管理员身份通过PowerShell):

New-NetFirewallRule -DisplayName "WSL" -Direction Inbound  -InterfaceAlias "vEthernet (WSL)"  -Action Allow

此命令起作用并添加新规则。

(Official)第2步:删除阻止到IDEA的入站流量(这是错误的)

说明中的下一步是删除阻止流量到IntelliJ IDEA的现有规则:

Get-NetFirewallRule | where DisplayName -ILike "idea*.exe" | Remove-NetFirewallRule

此命令不执行任何操作,因为筛选器部分where DisplayName -ILike "idea*.exe"与任何内容都不匹配。

DisplayName属性可能对应于防火墙控制面板中的Name列:

这样您就可以看到";IDEA*.exe&qot;不匹配那里。

如果我将搜索更改为:

Get-NetFirewallRule | where DisplayName -ILike "IntelliJ IDEA*"

然后,我确实会在外壳输出中返回所有四个规则:

PS C:Windowssystem32> Get-NetFirewallRule | where DisplayName -ILike "IntelliJ IDEA*"


Name                  : TCP Query User{6288ADD6-1B2E-4BFF-9317-AEEA34194E04}C:program filesjetbrainsintellij idea
                        community edition 2021.2inidea64.exe
DisplayName           : IntelliJ IDEA Community Edition 2021.2
Description           : IntelliJ IDEA Community Edition 2021.2
DisplayGroup          :
Group                 :
Enabled               : True
Profile               : Private
Platform              : {}
Direction             : Inbound
Action                : Allow
EdgeTraversalPolicy   : DeferToUser
LooseSourceMapping    : False
LocalOnlyMapping      : False
Owner                 :
PrimaryStatus         : OK
Status                : The rule was parsed successfully from the store. (65536)
EnforcementStatus     : NotApplicable
PolicyStoreSource     : PersistentStore
PolicyStoreSourceType : Local

Name                  : UDP Query User{1AE9E9C6-02EF-4C65-8781-B1050740E936}C:program filesjetbrainsintellij idea
                        community edition 2021.2inidea64.exe
DisplayName           : IntelliJ IDEA Community Edition 2021.2
Description           : IntelliJ IDEA Community Edition 2021.2
DisplayGroup          :
Group                 :
Enabled               : True
Profile               : Private
Platform              : {}
Direction             : Inbound
Action                : Allow
EdgeTraversalPolicy   : DeferToUser
LooseSourceMapping    : False
LocalOnlyMapping      : False
Owner                 :
PrimaryStatus         : OK
Status                : The rule was parsed successfully from the store. (65536)
EnforcementStatus     : NotApplicable
PolicyStoreSource     : PersistentStore
PolicyStoreSourceType : Local

Name                  : {386E3B53-5E4D-4939-8114-74499BDA8515}
DisplayName           : IntelliJ IDEA Community Edition 2021.2
Description           : IntelliJ IDEA Community Edition 2021.2
DisplayGroup          :
Group                 :
Enabled               : True
Profile               : Public
Platform              : {}
Direction             : Inbound
Action                : Block
EdgeTraversalPolicy   : Block
LooseSourceMapping    : False
LocalOnlyMapping      : False
Owner                 :
PrimaryStatus         : OK
Status                : The rule was parsed successfully from the store. (65536)
EnforcementStatus     : NotApplicable
PolicyStoreSource     : PersistentStore
PolicyStoreSourceType : Local

Name                  : {63ED0AB1-12B9-47F2-9810-D1D446EBF9D8}
DisplayName           : IntelliJ IDEA Community Edition 2021.2
Description           : IntelliJ IDEA Community Edition 2021.2
DisplayGroup          :
Group                 :
Enabled               : True
Profile               : Public
Platform              : {}
Direction             : Inbound
Action                : Block
EdgeTraversalPolicy   : Block
LooseSourceMapping    : False
LocalOnlyMapping      : False
Owner                 :
PrimaryStatus         : OK
Status                : The rule was parsed successfully from the store. (65536)
EnforcementStatus     : NotApplicable
PolicyStoreSource     : PersistentStore
PolicyStoreSourceType : Local

Step 2:删除阻止到IDEA的入站通信(右)

禁用这两个公共入站规则并启用新添加的WSL入站规则后,IDEA可以在之前出现连接错误的地方正确运行Java。

您可以通过以下方法之一实现对IDEA的这两个入站公共规则的相同禁用/删除:

Option 1:具有高级安全性的Windows Defender防火墙&>入站规则

在上图所示的视图中,右键单击规则,然后为公共配置文件上的每个入站规则选择禁用规则。

Option 2:通过PowerShell禁用

您可以通过PowerShell(以管理员身份)使用以下命令禁用相同的两个规则:

Get-NetFirewallProfile -Name Public | Get-NetFirewallRule | where DisplayName -ILike "IntelliJ IDEA*" | Disable-NetFirewallRule

Option 3:通过PowerShell删除

您可以使用以下命令通过PowerShell(以管理员身份)删除相同的两个规则:

Get-NetFirewallProfile -Name Public | Get-NetFirewallRule | where DisplayName -ILike "IntelliJ IDEA*" | Remove-NetFirewallRule

所有这三种方法对我都有效,并允许我启用所有Windows防火墙配置文件(域、专用、公共),并且Java现在可以在位于WSL2文件系统中的WSL2项目的IDEA中正确运行。

更新:我不得不从最新的2021.2版本回滚到2021.1.3,因为最新版本将失去连接到wsl2文件系统的能力,直到ws1重新启动。

我安装了两个版本,但我必须编辑防火墙规则以允许通信到2021.1.3程序(奇怪的是,防火墙中还将命名为2021.2!)并将公共配置文件(仅为私有)添加到允许规则。

这篇关于如何使用WSL2正确设置IntelliJ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆