Mac電腦做開發真的容易。
準備
電腦:MMP
開發工具:IntelliJ IDEA、JDK
伺服器:阿里雲(雙11買的)等
SpringBoot
建立一個HelloWorld


這裡基本都已經自動生成了,簡單介紹下:
Name:專案名稱
Type:我們是Maven構建的,那麼選擇第一個Maven Project
Packaging:打包型別,打包成Jar檔案
Java Version:jdk版本,選擇1.8
Language:開發語言,選擇Java
Group:對應pom檔案中的groupId,專案組織的唯一標識,對應Java包的結構
Artifact:對應pom檔案的artifactId,專案唯一標識,對應專案名稱
Version:專案版本,對應pom檔案的version
Description:專案描述,對應pom檔案的description
Package:包名



寫一個HelloWorld的Controller
package com.example.demo.controller;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author tongson
*/
@RestController
@EnableAutoConfiguration
public class HelloController {
@RequestMapping("/hello")
public String hello(){
return "hello,this is a SpringBoot demo";
}
}
複製程式碼
執行DemoApplication



到這裡已經把hello world執行起來了。十分簡單嘛。
問題來了,伺服器怎麼部署這專案呢。
打包成jar。
SpringBoot生成jar包(一鍵成jar)



Linux
將SpringBoot的jar上傳到Linux
scp命令
scp(secure copy)是一個基於 SSH 協議在網路之間進行安全傳輸的命令,其格式為“scp [引數] 本地檔案 遠端帳戶@遠端 IP 地址:遠端目錄”。
用scp直接在IntelliJ IDEA中的Terminal敲命令列就可以了

登入到伺服器上,咦,真的有。

linux下配置Java環境變數
wget命令
wget 命令用於在終端中下載網路檔案,格式為“wget [引數] 下載地址”。
下載jdk到Linux(百度jdk,上官網就有了)
下載.tar.gz
拷貝Url:download.oracle.com/otn-pub/jav…
下載到什麼地方呢?
1.root上。
2.root的/usr/local(使用者自行安裝的軟體,我被坑了很久)上

cd /usr/local/java
wget https://download.oracle.com/otn-pub/java/jdk/8u192-b12/750e1c8617c5452694857ad95c3ee230/jdk-8u192-linux-x64.tar.gz?AuthParam=1545665260_0fa8923d79e6f22414f76fe0114e68e5
複製程式碼

tar命令
tar 命令用於對檔案進行打包壓縮或解壓,格式為“tar [選項] [檔案]”。
在 Linux 系統中,常見的檔案格式比較多,其中主要使用的是.tar 或.tar.gz 或.tar.bz2 格式,我 們不用擔心格式太多而記不住,其實這些格式大部分都是由 tar 命令來生成的。
使用“tar -czvf 壓縮包名稱.tar.gz 要打包的目錄
”命令把指定的檔案進行打包壓縮;
相應的解壓命令為“tar-xzvf 壓縮 包名稱.tar.gz
”。
待下載成功了就可以把.tar.gz解壓。
配置root的環境變數
Vim 編輯器編寫和修改配置檔案
vim /etc/profile
複製程式碼

可以分別使用 a、i、o 三個鍵從命令模式切換到輸入模式。其中,a 鍵 與 i 鍵分別是在游標後面一位和游標當前位置切換到輸入模式,而 o 鍵則是在游標的下面再 建立一個空行。
a
複製程式碼

export JAVA_HOME=/usr/local/java/jdk1.8.0_192
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH
export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin
export PATH=$PATH:${JAVA_PATH}
複製程式碼
在編寫完之後,想要儲存並退出,必須先敲擊鍵盤 Esc 鍵從輸入模式返回命令模式。
Esc
複製程式碼
然後再輸入:wq!切換到末行模式才能完成儲存退出操作
:wq!
複製程式碼

使環境變數生效

source /etc/profile
複製程式碼
測試是否配置成功
①javac
②java -version
③echo $PATH
看看自己剛剛設定的的環境變數配置是否都正確
Linux下執行jar包
java -jar demo-0.0.1-SNAPSHOT.jar
複製程式碼


訪問
ip地址不好意思暴露

怎麼訪問不了呢??

開放埠號
要阿里雲開放埠號,哎呀。
大功告成
