如何使用​win10内置的linux系统启动spring-boot项目

 更新时间:2020年07月01日 09:39:54   作者:李通  
这篇文章主要介绍了如何使用​win10内置的linux系统启动spring-boot项目,需要的朋友可以参考下

1.安装win10内置linux子系统

1.1.安装linux子系统

1.1.1.升级或者重装linux系统

1.系统要求

需要升级win10到一周年纪念版,或者 重装系统

2.重装系统

笔者结果测试发现下面的系统重装后可以启用linux子系统

cn_windows_10_enterprise_version_1607_updated_jul_2016_x64_dvd_9057083.iso
cn_windows_10_multi-edition_vl_version_1709_updated_sept_2017_x64_dvd_100090774.iso

1.1.2.启用linux子系统

step1.启用开发人员模式

(16215版之后不再需要开发人员模式)

设置-->更新和安全-->针对开发人员

step2.启用linux子系统

控制面板-->程序和功能-->启用或关闭windows功能

1.1.3.在线安装ubuntu系统

打开Microsoft Store安装ubuntu系统

1.1.4.离线安装ubuntu系统

下载安装包,下载自己想要安装的Linux系统。

参考链接:https://docs.microsoft.com/en...

下载Ubuntu 16.04.

Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1604 -OutFile Ubuntu.appx -UseBasicParsing

也可以使用curl下载,但是需要先安装curl

curl.exe -L -o ubuntu-1604.appx https://aka.ms/wsl-ubuntu-1604

安装

Add-AppxPackage .\app_name.appx

1.1.5.启动ubuntu系统

启动ubuntu系统

安装完成后打开搜索菜单,输入系统名字搜索启动

输出需要设置的用户和密码

你相信吗,仅仅只有15.4MB

安装目录

C:\Users\Administrator\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc

home目录

C:\Users\Administrator\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc\LocalState\rootfs\home

1.2.开启ssh-server

1.2.1.相互复制文件

ubuntu的bash窗口窗与在xshell不同,通过shift+v无法黏贴,并且在输入界面鼠标右键无法使用。粘贴文件的方法如下

右击标题栏==> Edit(编辑) ==> Mark/Paste(标记并复制/粘贴)操作

这样还是很麻烦,可以调整对话框,在弹出的菜单中有一个Properties对话框属性菜单,点击进入下图

勾选快速编辑、快速插入模式,这两种模式支持鼠标右键选中,左键黏贴操作。

最后,最好的方式是,在ubuntu上启动ssh服务,通过xshell连接上操作会更好。

1.2.2.修改apt源

参考链接

https://developer.aliyun.com/...

用你熟悉的编辑器打开:

/etc/apt/sources.list

替换默认的archive.ubuntu.com为mirrors.aliyun.com

修改后的内容

ubuntu18.04

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

ubuntu 20.04(focal)

deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

更新

apt-get update

1.2.3.启用ssh

1.安装ssh

apt-get -y install openssh-server

2.修改配置文件,一般不需要修改

cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
vi /etc/ssh/sshd_config
# 修改端口号,避免和 Windows ssh 服务端口冲突
Port 2222
#StrictModes yes # 注释
# 使用密码登录
PasswordAuthentication yes 
# 允许使用 root 用户登录
PermitRootLogin yes

3.设置root账号密码

sudo -s
passwd root

4.启动ssh

service ssh start

5.如果提示“sshd error: could not load host key”,则用下面的命令重新生成

rm /etc/ssh/ssh*key
dpkg-reconfigure openssh-server

使用xshell连接127.0.0.1输入账号和密码即可

1.2.4.配置PS1变量

自行百度什么事linux的PS1变量

export PS1="\[\e[1;32;40m\][\u@\h \W]\\$ \[\e[m\]"

2.搭建开发环境

2.1.搭建java开发环境

2.1.1.安装java和maven

mkdir /usr/java
tar -xf jdk-8u211-linux-x64.tar.gz -C /usr/java/
mdkir /usr/maven
tar -xf litongjava-apache-maven-3.3.9.tar.gz -C /usr/maven/

配置环境变量

export JAVA_HOME=/usr/java/jdk1.8.0_211
export M2_HOME=/usr/maven/apache-maven-3.3.9
export PATH=$JAVA_HOME/bin:$M2_HOME/bin:$PATH

配置maven使用windows的maven本地库目录,maven本地库在linux中对应的目录是/mnt/d/dev_mavenRepository/

settings.xml的内容如下

cat /usr/maven/apache-maven-3.3.9/conf/settings.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>/mnt/d/dev_mavenRepository/</localRepository>
 <pluginGroups> 
 </pluginGroups>
 <proxies>
 </proxies>
 <servers>
 </servers>
 <mirrors>
 <mirror>
  <id>aliyun</id>
  <name>aliyun</name>
  <mirrorOf>*</mirrorOf>
  <url>https://maven.aliyun.com/repository/public</url>
 </mirror>
 </mirrors>
 <profiles>
 </profiles>
</settings>

2.1.2.打包和启动spring-boot项目

进行项目目录执行下面的命令打包项目

mvn clean package -DskipTests

进入target目录启动项目

cd target/
java -jar *.jar

可以明显的看出,java程序使用了近1G的内存

总结

到此这篇关于如何使用​win10内置的linux系统启动spring-boot项目的文章就介绍到这了,更多相关win10 linux启动spring-boot项目内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • Bash中尖括号的更多使用方法

    Bash中尖括号的更多使用方法

    这篇文章主要给大家介绍了关于Bash中尖括号的更多使用方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
    2019-02-02
  • linux expect实现登陆远程主机并执行命令示例代码

    linux expect实现登陆远程主机并执行命令示例代码

    这篇文章主要给大家介绍了linux expect实现登陆远程主机并执行命令的相关资料,文中给出了详细的示例代码供大家参考学习,对大家具有一定的参考学习价值,需要的朋友们下面来一起看看吧。
    2017-06-06
  • 解决CentOS 7升级Python到3.6.6后yum出错问题总结

    解决CentOS 7升级Python到3.6.6后yum出错问题总结

    这篇文章主要介绍了CentOS 7升级Python到3.6.6后yum出错问题解决总结,本文给大家介绍的非常详细具有一定的参考借鉴价值,需要的朋友可以参考下
    2019-09-09
  • 详解CentOS7防火墙管理firewalld

    详解CentOS7防火墙管理firewalld

    本篇文章主要介绍了CentOS7防火墙管理firewalld,centos 7中防火墙是一个非常的强大的功能了,有兴趣的可以了解一下。
    2016-12-12
  • Linux NFS服务器安装与配置思路分析

    Linux NFS服务器安装与配置思路分析

    NFS 是Network File System的缩写,即网络文件系统,可以让不同的客户端挂载使用同一个目录,作为共享存储使用,这样可以保证不同的节点客户端数据一致性,在集群架构中经常用到.这篇文章主要介绍了Linux NFS服务器安装与配置思路,需要的朋友可以参考下
    2016-10-10
  • linux最快的文本搜索神器ripgrep(grep的最好代替者)

    linux最快的文本搜索神器ripgrep(grep的最好代替者)

    这篇文章主要介绍了linux最快的文本搜索神器ripgrep(grep的最好代替者),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-11-11
  • Linux(CentOS)环境下安装下载Nginx并配置

    Linux(CentOS)环境下安装下载Nginx并配置

    本篇文章主要介绍了Linux(CentOS)环境下安装下载Nginx并配置 ,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-02-02
  • 阿里云ubuntu16.04如何搭建pptpd服务

    阿里云ubuntu16.04如何搭建pptpd服务

    这篇文章主要介绍了阿里云ubuntu16.04搭建pptpd,需要的朋友可以参考下
    2019-11-11
  • CentOS+Nginx+PHP+MySQL标准生产环境配置方法

    CentOS+Nginx+PHP+MySQL标准生产环境配置方法

    这个可比网上流传的什么一键安装包要好得多,强烈推荐此法安装,适合所有菜鸟和高手。我服务器上全用的源代码编译安装,也好不到哪去,还很费劲。我这个装完已经包含 php 的一些常用扩展, PDO,eaccelerator,memcache,tidy等等。
    2010-02-02
  • Tomcat中的catalina.bat原理详细解析

    Tomcat中的catalina.bat原理详细解析

    这篇文章主要给大家详细介绍了关于Tomcat中catalina.bat的原理,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们可以参考借鉴,下面随着小编来一起学习学习下吧。
    2017-08-08

最新评论