简体   繁体   English

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

[英]Run and Debug Java in WSL 2 with Intellij IDEA on Windows 10

Intellij IDEA is installed on Windows. Intellij IDEA 安装在 Windows 上。 The java application built with maven requires native libraries (with JNI) and runs on Ubuntu.使用 maven 构建的 java 应用程序需要本机库(带有 JNI)并在 Ubuntu 上运行。

Using maven and git on Windows is fine.在 Windows 上使用 maven 和 git 很好。 How can I point Intellij IDEA to use the JDK from WSL so I can create a run/debug configuration that uses the WSL?如何让 Intellij IDEA 使用 WSL 中的 JDK,以便创建使用 WSL 的运行/调试配置?

Deploy your app on WSL with Power Shell, and remote debug使用 Power Shell 在 WSL 上部署您的应用,并进行远程调试

  1. Install Intellij IDEA with version >= 2021.1.安装版本 >= 2021.1 的 Intellij IDEA。
  2. Configure WSL.配置 WSL。 To work with WSL 2, your Windows version should be 10 build 18917 or later.要使用 WSL 2,您的 Windows 版本应该是 10 build 18917 或更高版本。 Make sure you add the needed JDK version in WSL.确保在 WSL 中添加所需的 JDK 版本。 In order to use Maven, You also need to add a path variable export M2_HOME=/path/to/maven to the.profile file.为了使用Maven,还需要在.profile文件中添加路径变量export M2_HOME=/path/to/maven。
  3. Create, open and develop the project in corresponding WSL environment.在相应的 WSL 环境中创建、打开和开发项目。
  4. Select the project SDK as the JDK configured in WSL. Select 项目 SDK 作为 WSL 中配置的 JDK。
  5. Ensure that firewalls allow connections using WSL.确保防火墙允许使用 WSL 进行连接。

More details: https://www.jetbrains.com/help/idea/2021.1/how-to-use-wsl-development-environment-in-product.html更多详情: https://www.jetbrains.com/help/idea/2021.1/how-to-use-wsl-development-environment-in-product.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM