在 Windows 10 上使用 Intellij IDEA 在 WSL 2 中运行和调试 Java

Pat*_*ick 10 java debugging intellij-idea windows-subsystem-for-linux wsl-2

Intellij IDEA 安装在 Windows 上。使用 maven 构建的 java 应用程序需要本机库(使用 JNI)并在 Ubuntu 上运行。

在 Windows 上使用 maven 和 git 很好。如何让 Intellij IDEA 使用 WSL 中的 JDK,以便我可以创建使用 WSL 的运行/调试配置?

kur*_*boh 0

  1. 安装 Intellij IDEA 版本 >= 2021.1。
  2. 配置 WSL。要使用 WSL 2,您的 Windows 版本应该是 10 build 18917 或更高版本。确保在 WSL 中添加所需的 JDK 版本。为了使用Maven,您还需要在.profile文件中添加路径变量export M2_HOME=/path/to/maven。
  3. 在相应的WSL环境中创建、打开和开发项目。
  4. 选择项目 SDK 作为 WSL 中配置的 JDK。
  5. 确保防火墙允许使用 WSL 的连接。

更多详细信息:https://www.jetbrains.com/help/idea/2021.1/how-to-use-wsl-development-environment-in-product.html