IDEA+wsl2 环境搭建求助 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
insert000
V2EX    JetBrains

IDEA+wsl2 环境搭建求助

  •  
  •   insert000 20 小时 35 分钟前 923 次点击

    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\aven\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 条附言    5 小时 35 分钟前
    解决了,在 Settings->build->maven->runner->jre 下选择 WSL 的 JDK 就行
    20 条回复    2025-12-17 17:31:12 +08:00
    yukunZhan9
        1
    yukunZhan9  
       20 小时 24 分钟前
    你这 idea 是用的 windows 本地的吗?推荐使用 jebrains gateway 连到 wsl 里的 idea 做开发就不会有这个问题了
    insert000
        2
    insert000  
    OP
       20 小时 24 分钟前
    @yukunZhan9 对本地的 idea
    yukunZhan9
        3
    yukunZhan9  
       20 小时 17 分钟前
    insert000
        4
    insert000  
    OP
       19 小时 55 分钟前
    @yukunZhan9 好吧,这样体验太差了
    Mogugugugu
        5
    Mogugugugu  
       19 小时 40 分钟前
    你这样性能很差的,各种奇葩问题,换 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
       19 小时 33 分钟前
    @Mogugugugu 我试了一下,gateway + wsl2 ,总感觉不跟手,有点延迟的。那我还是本地老实的安装吧
    shunia
        7
    shunia  
       19 小时 28 分钟前
    @Mogugugugu #5 感谢分享。有点没想到 2025 年了 JB 还没有解决这个问题。
    holyliao
        8
    holyliao  
       18 小时 53 分钟前
    我是使用 wslg, idea 都安装在子系统中,凑合能用
    Plutooo
        9
    Plutooo  
       18 小时 0 分钟前
    好奇这样的好处是啥
    lxqxqxq
        10
    lxqxqxq  
       17 小时 45 分钟前
    @insert000 #6 VS Code + WSL2 正解
    lisxour
        11
    lisxour  
       17 小时 37 分钟前
    @Plutooo 玩得多 wsl 的都知道,这是纯搞自己而已,很多人都把 wsl 当成是真正的完整独立 linux 了
    WashFreshFresh
        12
    WashFreshFresh  
       16 小时 18 分钟前
    idea/jdk/maven/项目都装在了 wslg 里,强行工作了一年,只能说很痛苦,一方面是时不时卡死,一方面是输入法用起来很痛苦,不跟光标,至于为啥这么痛苦还坚持了一年,因为 Windows 编译启服务耗时 200s ,linux 60s 不到,后来用了 JRebel 就只用 Windows 了。
    Mjhhh
        13
    Mjhhh  
       15 小时 48 分钟前
    同样是 IDEA 2025.1 + wsl2 开发,目前没有很顺畅,性能也很好
    orrinex
        14
    orrinex  
       15 小时 31 分钟前
    我用 windows 下的 idea 打开 wsl2 下的项目,根据官方的说法是没问题的,但实际用下来全是 bug 。

    使用 gateway 去远程到 wsl2 勉强可用,就是插件有的有 bug 。
    zed1018
        15
    zed1018  
       13 小时 31 分钟前
    我建议是在 ws 里装 idea 直接走 wslg 。唯独就是输入法我没搞好,后来还是用 gateway 了
    insert000
        16
    insert000  
    OP
       13 小时 6 分钟前
    @Mjhhh 你这样可以正常使用 maven 吗?
    Mjhhh
        17
    Mjhhh  
       12 小时 45 分钟前
    @insert000 #16 可以的,你试试在 idea 中双击 ctrl ,输入 mvn --version ,看看用的是 wsl 中的 maven ,还是 idea 的 maven ,我建议是用 wsl 的
    insert000
        18
    insert000  
    OP
       12 小时 43 分钟前
    @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  
       12 小时 33 分钟前
    @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  
       12 小时 9 分钟前
    虽然是把代码、JDK 和 Maven 都放在了 Ubuntu (WSL2) 里,但 IDEA (运行在 Windows 上)错误地试图用 Windows 的方式(调用 cmd.exe 和 mvn.cmd )去执行位于网络共享路径( UNC 路径 \\wsl.localhost\...)下的程序。这是关键问题所在的。
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     909 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 35ms UTC 21:40 PVG 05:40 LAX 13:40 JFK 16:40
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86