IDEA 安装在物理机器上,JDK 和 maven 都安装在 WSL2 子系统的 Ubuntu 上。项目也在 Ubuntu 子系统的目录中,配置如截图,运行 IDEA 自带的 MAVEN 插件 clean ,test 等均报错
\\wsl.localhost\Ubuntu-24.04\home\abner\app\apache-maven-3.9.11\bin\mvn.cmd -Didea.version=2025.3 -Dmaven.ext.class.path=E:\soft\JetBrains\IntelliJ IDEA 2025.3\plugins\maven\lib\maven-event-listener.jar -Djansi.passthrough=true -Dstyle.color=always -s \\wsl.localhost\Ubuntu-24.04\home\abner\.m2\settings.xml -Dmaven.repo.local=\\wsl.localhost\Ubuntu-24.04\home\abner\.m2\repository clean -f pom.xml
'\\wsl.localhost\Ubuntu-24.04\home\abner\project\java\hd\urthink-base-admin'
用作为当前目录的以上路径启动了 CMD.EXE 。
UNC 路径不受支持。默认值设为 Windows 目录。
The JAVA_HOME environment variable is not defined correctly,
this environment variable is needed to run this program.
1
yukunZhan9 11 小时 58 分钟前
你这 idea 是用的 windows 本地的吗?推荐使用 jebrains gateway 连到 wsl 里的 idea 做开发就不会有这个问题了
|
2
insert000 OP @yukunZhan9 对本地的 idea
|
3
yukunZhan9 11 小时 52 分钟前
|
4
insert000 OP @yukunZhan9 好吧,这样体验太差了
|
5
Mogugugugu 11 小时 14 分钟前
你这样性能很差的,各种奇葩问题,换 gateway,但是 gateway + wsl2 也问题挺多的,内存小的机器不建议搞。
wsl2 的核心玩法都是把整个环境+代码全部放到 wsl2 中,然后在 Windows 中远程连接,像是 VS Code 和 JBd 都是在 wsl2 中单独启动一个 Server,Windows 中的相当于客户端,所有的编译等操作都放在 WSL2 里面的 Server 端进行。 不是劝退你哈,IDEA+WSL2 无论使用哪种解决方案都有不爽的点,之前折腾过,全部放弃了。用 VS Code + WSL2 写 Java 都比 IDEA+WSL2 的方式要舒服,这俩就天生不配。 |
6
insert000 OP @Mogugugugu 我试了一下,gateway + wsl2 ,总感觉不跟手,有点延迟的。那我还是本地老实的安装吧
|
7
shunia 11 小时 2 分钟前
@Mogugugugu #5 感谢分享。有点没想到 2025 年了 JB 还没有解决这个问题。
|
8
holyliao 10 小时 27 分钟前
我是使用 wslg, idea 都安装在子系统中,凑合能用
|
9
Plutooo 9 小时 34 分钟前
好奇这样的好处是啥
|
12
WashFreshFresh 7 小时 53 分钟前
idea/jdk/maven/项目都装在了 wslg 里,强行工作了一年,只能说很痛苦,一方面是时不时卡死,一方面是输入法用起来很痛苦,不跟光标,至于为啥这么痛苦还坚持了一年,因为 Windows 编译启服务耗时 200s ,linux 60s 不到,后来用了 JRebel 就只用 Windows 了。
|
13
Mjhhh 7 小时 22 分钟前
|
14
orrinex 7 小时 5 分钟前
我用 windows 下的 idea 打开 wsl2 下的项目,根据官方的说法是没问题的,但实际用下来全是 bug 。
使用 gateway 去远程到 wsl2 勉强可用,就是插件有的有 bug 。 |
15
zed1018 5 小时 5 分钟前
我建议是在 ws 里装 idea 直接走 wslg 。唯独就是输入法我没搞好,后来还是用 gateway 了
|
17
Mjhhh 4 小时 20 分钟前
@insert000 #16 可以的,你试试在 idea 中双击 ctrl ,输入 mvn --version ,看看用的是 wsl 中的 maven ,还是 idea 的 maven ,我建议是用 wsl 的
|
18
insert000 OP @Mjhhh \\wsl.localhost\Ubuntu-24.04\home\abner\app\apache-maven-3.9.11\bin\mvn.cmd -Didea.version=2025.3 -Dmaven.ext.class.path=E:\soft\JetBrains\IntelliJ IDEA 2025.3\plugins\maven\lib\maven-event-listener.jar -Djansi.passthrough=true -Dstyle.color=always -s \\wsl.localhost\Ubuntu-24.04\home\abner\.m2\settings.xml -Dmaven.repo.local=\\wsl.localhost\Ubuntu-24.04\home\abner\.m2\repository clean -f pom.xml
'\\wsl.localhost\Ubuntu-24.04\home\abner\project\java\hd\urthink-base-admin' 用作为当前目录的以上路径启动了 CMD.EXE 。 UNC 路径不受支持。默认值设为 Windows 目录。 The JAVA_HOME environment variable is not defined correctly, this environment variable is needed to run this program. 看报错是走的 WSL 的 maven |
19
Mjhhh 4 小时 7 分钟前
@insert000 #18 这是我执行 mvn --version 打印的信息,给你参考下/bin/sh /usr/share/maven/bin/mvn -Didea.version=2025.2.2 -Dmaven.ext.class.path=/tmp/CKHrIJmaven-event-listener.jar -Djansi.passthrough=true -Dstyle.color=always -s /home/user/.m2/settings.xml -Dmaven.repo.local=/home/user/.m2/repository --version -f pom.xml
Apache Maven 3.6.3 Maven home: /usr/share/maven Java version: 17.0.9, vendor: GraalVM Community, runtime: /home/user/.sdkman/candidates/java/17.0.9-graalce Default locale: en, platform encoding: UTF-8 OS name: "linux", version: "6.6.87.2-microsoft-standard-wsl2", arch: "amd64", family: "unix" |
20
XR843 3 小时 43 分钟前
虽然是把代码、JDK 和 Maven 都放在了 Ubuntu (WSL2) 里,但 IDEA (运行在 Windows 上)错误地试图用 Windows 的方式(调用 cmd.exe 和 mvn.cmd )去执行位于网络共享路径( UNC 路径 \\wsl.localhost\...)下的程序。这是关键问题所在的。
|