記一次二次開發Spring項目的,用vscode配置環境過程。因為vscode是用json文件保存的配置。好多都過時了。強行提筆記錄一下
安裝組件
一個java, 一個spring boot
安裝Maven和Java
java這個簡單
maven
配置環境變量,如果是zshrc就用如下配置
# maven home
export M2_HOME=/Users/xxx/Documents/Maven
export PATH=$PATH:$M2_HOME/bin
# end
http://maven.apache.org/download.cgi
主要是修改源為阿里
<!-- 阿里雲倉庫 -->
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>*</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
<!-- 中央倉庫1 -->
<mirror>
<id>repo1</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo1.maven.org/maven2/</url>
</mirror>
<!-- 中央倉庫2 -->
<mirror>
<id>repo2</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo2.maven.org/maven2/</url>
</mirror>
然后配置vscode配置maven
復制下面文件settings.json里面,修改自己的 java.home
以及maven地址
"maven.excludedFolders": [
"**/.*",
"**/node_modules",
"**/target",
"**/bin",
{
"workbench.iconTheme": "vscode-icons",
"workbench.startupEditor": "newUntitledFile",
"java.errors.incompleteClasspath.severity": "ignore",
"workbench.colorTheme": "Atom One Dark",
"java.home":"/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home",
"java.configuration.maven.userSettings": "/Users/admin/Documents/Maven/conf/settings.xml",
"maven.executable.path": "/Users/admin/Documents/Maven/bin/mvn",
"maven.terminal.useJavaHome": true,
"maven.terminal.customEnv": [
{
"environmentVariable": "JAVA_HOME",
"value": "/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home"
}
],
}
],
編譯
在maven窗口右鍵點擊 install
即可。
運行
進入到vscode命令行
然后輸入spring
選擇需要引入的包,引入如下幾個包即可滿足web開發:
DevTools(代碼修改熱更新,無需重啟)、Web(集成tomcat、SpringMVC)、Lombok(智能生成setter、getter、toString等接口,無需手動生成,代碼更簡介)、Thymeleaf (模板引擎)。
選擇好要引入的包后直接回車,在新彈出的窗口中選擇項目路徑,至此Spring Boot項目創建完成。
如果是導入已經存在的Spring boot項目,則導入后在SPRING-BOOT DASHBOARD可以看到很多的server,右鍵就可以start或者debug了。