wsl2 安装jdk,maven

2021-12-26

总结:嗯~,不要作死,放弃wsl2 安装java环境(老老实实的本地安装吧),idea使用wsl2简直就是灾难,如果你用vscode开发java那另说 👍

环境

sudo apt update
sudo apt install default-jre
java -version
# openjdk version "11.0.13" 2021-10-19
sudo apt install default-jdk
javac -version
# javac 11.0.13


# 查看java安装位置
pdate-alternatives --config java
# /usr/lib/jvm/java-11-openjdk-amd64/bin/java

# 设置 JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
vim ~/.zshrc
source ~/.zshrc

echo $JAVA_HOME 
# /usr/lib/jvm/java-11-openjdk-amd64

# 安装maven
apt-get install maven -y
mvn -version
#Apache Maven 3.6.3
# 设置 M2_HOME=""
vim ~/.zshrc
source ~/.zshrc

设置maven 阿里源

# ~/.m2/settings.xml
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <localRepository/>
  <interactiveMode/>
  <usePluginRegistry/>
  <offline/>
  <pluginGroups/>
  <servers/>
  <mirrors>
    <mirror>
     <id>aliyunmaven</id>
     <mirrorOf>central</mirrorOf>
     <name>阿里云公共仓库</name>
     <url>https://maven.aliyun.com/repository/central</url>
    </mirror>
    <mirror>
      <id>repo1</id>
      <mirrorOf>central</mirrorOf>
      <name>central repo</name>
      <url>http://repo1.maven.org/maven2/</url>
    </mirror>
    <mirror>
     <id>aliyunmaven</id>
     <mirrorOf>apache snapshots</mirrorOf>
     <name>阿里云阿帕奇仓库</name>
     <url>https://maven.aliyun.com/repository/apache-snapshots</url>
    </mirror>
  </mirrors>
  <proxies/>
  <activeProfiles/>
  <profiles>
    <profile>  
        <repositories>
           <repository>
                <id>aliyunmaven</id>
                <name>aliyunmaven</name>
                <url>https://maven.aliyun.com/repository/public</url>
                <layout>default</layout>
                <releases>
                        <enabled>true</enabled>
                </releases>
                <snapshots>
                        <enabled>true</enabled>
                </snapshots>
            </repository>
            <repository>
                <id>MavenCentral</id>
                <url>http://repo1.maven.org/maven2/</url>
            </repository>
            <repository>
                <id>aliyunmavenApache</id>
                <url>https://maven.aliyun.com/repository/apache-snapshots</url>
            </repository>
        </repositories>             
     </profile>
  </profiles>
</settings>

在项目下面maven install 安装依赖

遇到问题了? 可以直接联系我

评论区