IDEA配置web專案、部署Tomcat、配置maven
剛開始學習使用IDEA配置web專案,經過同事的幫助和網上的教程,結合自己的實踐,將IDEA 配置web專案、部署Tomcat、配置maven三部分內容做一個總結。
一、配置web專案
使用命令列將git專案clone下來,用intellij idea import project或者open所下載的專案。
1.配置Project Structure.
- 1.1 Project子選項
其中,第二個要選的language level:限定專案編譯檢查時最低要求的 JDK 特性。 現在假設我們有一個專案程式碼使用的 JDK 8 新特性:lambda 語法,但是 JDK 選擇的卻是 JDK 7,即使 language level 選擇了 8 - Lambdas,type annotation etc.,也是沒有多大意義的,一樣會編譯報錯。
1.2 modules子選項(sources、 path、dependencies )
- –sources標籤頁中配置專案結構
(主要配置需編譯的Java檔案和配置檔案)
excluded是讓.idea跳過執行 –Paths標籤頁中配置編譯後文件輸出路徑
–Dependencies標籤頁中配置依賴關係
若沒有maven,手動配置是要加上jdk和web-inf/lib的jar包
1.3在Artifacts項中設定專案的部署配置
二、tomcat配置
在介面右上角點選圖示出開啟執行環境配置
記得在右邊Application context 中輸入專案的啟動地址 記得加“/”
配置tomcat路徑、埠
配置完成後點選執行tomcat即可
三、maven
maven的用處:
不用我們自己去download jar包,而是通過maven提供的pom.xml去配置jar包資訊,然後maven通過pom.xml配置資訊和規則,通過maven的命令,最後從maven的中央jar包倉庫download到你的maven本地倉庫,最後被我們自動依賴到專案中從而被使用。
解壓
在系統變數中新建M2_HOME、在Path中新增 %M2_HOME%\bin
—在cmd命令列中輸入mvn –version檢測是否安裝配置成功。
3.2 maven配置檔案
maven需要配置的檔案主要集中在pom.xml和settings.xml中.
settings.xml在conf子目錄下面,是Maven的基本配置,是一個包含了註釋和例子的模板,你可以快速的修改它來達到你的要求。
<settings xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository/> 本地庫的儲存位置,也就是maven主要的jar儲存位置
<interactiveMode/> Maven是否需要和使用者互動以獲得輸入
<usePluginRegistry/>Maven是否需要使用plugin-registry.xml檔案來管理外掛版本
<offline/>表示Maven是否需要在離線模式下執行
<pluginGroups/>當我們使用某個外掛,並且沒有在命令列為其提供組織Id(groupId)的時候,Maven就會使用該列表
<servers/>配置服務端的一些設定
<mirrors/> 映象庫
<proxies/> 用來配置不同的代理
<profiles/> 根據環境引數來調整構建配置的列表
<activeProfiles/>手動啟用profiles的列表
</settings>
實際應用中,經常使用的是<localRepository>、<servers>、<mirrors>、<profiles>
有限幾個節點,其他節點使用預設值足夠應對大部分的應用場景。我本機例項:
localrepository:
mirror:公司映象庫
profiles:包含了啟用(activation),倉庫(repositories),外掛倉庫(pluginRepositories)和屬性(properties)共四個子元素元素,repositories 和pluginRepositories 定義其他開發庫和外掛開發庫。對於團隊來說,肯定有自己的開發庫。可以通過此配置來定義。
<profiles>
<profile>
<id>dev</id>
<repositories>
<repository>
<id>nexus</id>
<name>local private nexus</name>
<url>http://nexus.it.taikang.com/content/groups/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<url>http://nexus.it.taikang.com/content/groups/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
3.3 IDE中設定maven
—開啟-File-Settings
經過一番折騰,我一個做前端的終於可以開始幹活了