首页 注册 登录
V2EX = way to explore V2EX 是一个关于分享和探索的地方
现在注册 已注册用户请 登录
V2EX JetBrains

IDEA+wsl2 环境搭建求助

insert000 · 2025 年 12 月 17 日 · 1651 次点击

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. 

图片配置: https://imgur.com/a/daAL0kZ

第 1 条附言 · 2025 年 12 月 18 日
解决了,在 Settings->build->maven->runner->jre 下选择 WSL 的 JDK 就行
24 条回复 2026年01月05日 00:25:27 +08:00
yukunZhan9
1
yukunZhan9 2025 年 12 月 17 日
你这 idea 是用的 windows 本地的吗?推荐使用 jebrains gateway 连到 wsl 里的 idea 做开发就不会有这个问题了
insert000
2
insert000
OP
2025 年 12 月 17 日
@yukunZhan9 对本地的 idea
yukunZhan9
3
yukunZhan9 2025 年 12 月 17 日
insert000
4
insert000
OP
2025 年 12 月 17 日
@yukunZhan9 好吧,这样体验太差了
Mogugugugu
5
Mogugugugu 2025 年 12 月 17 日
你这样性能很差的,各种奇葩问题,换 gateway,但是 gateway + wsl2 也问题挺多的,内存小的机器不建议搞。

wsl2 的核心玩法都是把整个环境+代码全部放到 wsl2 中,然后在 Windows 中远程连接,像是 VS Code 和 JBd 都是在 wsl2 中单独启动一个 Server,Windows 中的相当于客户端,所有的编译等操作都放在 WSL2 里面的 Server 端进行。

不是劝退你哈,IDEA+WSL2 无论使用哪种解决方案都有不爽的点,之前折腾过,全部放弃了。用 VS Code + WSL2 写 Java 都比 IDEA+WSL2 的方式要舒服,这俩就天生不配。
insert000
6
insert000
OP
2025 年 12 月 17 日
@Mogugugugu 我试了一下,gateway + wsl2 ,总感觉不跟手,有点延迟的。那我还是本地老实的安装吧
shunia
7
shunia 2025 年 12 月 17 日
@Mogugugugu #5 感谢分享。有点没想到 2025 年了 JB 还没有解决这个问题。
holyliao
8
holyliao 2025 年 12 月 17 日
我是使用 wslg, idea 都安装在子系统中,凑合能用
Plutooo
9
Plutooo 2025 年 12 月 17 日
好奇这样的好处是啥
lxqxqxq
10
lxqxqxq 2025 年 12 月 17 日
@insert000 #6 VS Code + WSL2 正解
lisxour
11
lisxour 2025 年 12 月 17 日
@Plutooo 玩得多 wsl 的都知道,这是纯搞自己而已,很多人都把 wsl 当成是真正的完整独立 linux 了
WashFreshFresh
12
WashFreshFresh 2025 年 12 月 17 日
idea/jdk/maven/项目都装在了 wslg 里,强行工作了一年,只能说很痛苦,一方面是时不时卡死,一方面是输入法用起来很痛苦,不跟光标,至于为啥这么痛苦还坚持了一年,因为 Windows 编译启服务耗时 200s ,linux 60s 不到,后来用了 JRebel 就只用 Windows 了。
Mjhhh
13
Mjhhh 2025 年 12 月 17 日
同样是 IDEA 2025.1 + wsl2 开发,目前没有很顺畅,性能也很好
orrinex
14
orrinex 2025 年 12 月 17 日
我用 windows 下的 idea 打开 wsl2 下的项目,根据官方的说法是没问题的,但实际用下来全是 bug 。

使用 gateway 去远程到 wsl2 勉强可用,就是插件有的有 bug 。
zed1018
15
zed1018 2025 年 12 月 17 日
我建议是在 ws 里装 idea 直接走 wslg 。唯独就是输入法我没搞好,后来还是用 gateway 了
insert000
16
insert000
OP
2025 年 12 月 17 日
@Mjhhh 你这样可以正常使用 maven 吗?
Mjhhh
17
Mjhhh 2025 年 12 月 17 日
@insert000 #16 可以的,你试试在 idea 中双击 ctrl ,输入 mvn --version ,看看用的是 wsl 中的 maven ,还是 idea 的 maven ,我建议是用 wsl 的
insert000
18
insert000
OP
2025 年 12 月 17 日
@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
Mjhhh
19
Mjhhh 2025 年 12 月 17 日
@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"
XR843
20
XR843 2025 年 12 月 17 日
虽然是把代码、JDK 和 Maven 都放在了 Ubuntu (WSL2) 里,但 IDEA (运行在 Windows 上)错误地试图用 Windows 的方式(调用 cmd.exe 和 mvn.cmd )去执行位于网络共享路径( UNC 路径 \\wsl.localhost\...)下的程序。这是关键问题所在的。
hopeT
21
hopeT 2025 年 12 月 26 日
捣鼓了一下,V 友们有遇到这个问题么,我用 maven 可以编译成功,但用 idea 原生的构建,就提示未能找到兼容的 JDK
insert000
22
insert000
OP
2025 年 12 月 26 日
@hopeT 不行,一样,提示 JDK 问题。后来放弃了
heyline
23
heyline 7 天前
请问现在用的什么方案
insert000
24
insert000
OP
6 天前
@heyline 没用了,直接用本地系统
关于 · 帮助文档 · 自助推广系统 · 博客 · API · FAQ · Solana · 2728 人在线 最高记录 6679 · Select Language 创意工作者们的社区 World is powered by solitude VERSION: 3.9.8.5 · 25ms · UTC 03:45 · PVG 11:45 · LAX 19:45 · JFK 22:45
♥ Do have faith in what you're doing.

AltStyle によって変換されたページ (->オリジナル) /