




下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、MavenWeb 項(xiàng)目部署到 Tomcat本文標(biāo)簽:MavenJava通過 Maven 來搭建項(xiàng)目是越來越多人的選擇,我也就湊了一下熱鬧,用 maven 來搭建了項(xiàng)目,發(fā)現(xiàn)還挺好用,但是也遇到了很多問題,下面記錄一下 Web 項(xiàng)目部署到 Tomcat 下的問題。1、普通的 WE 歐目,就是雖然是用 maven 搭建的,但是沒有使用 profiles.xml 文件來配置參數(shù)。這樣的項(xiàng)目可以通過以下的方式進(jìn)行部署:直接 mvncleanpackage-DskipTests,進(jìn)行打包,1)然后在可以把 war 包拷到 tomcat 目錄下的 Webapp 目錄下2)修改 tomcat 目錄下的 co
2、nf 目錄下的 server.xml 文件,在 Host 標(biāo)簽之間添加如下一句話:ContextdocBase=D:IdeaProjectsTestexampleexample-webtargetexample-webreloadable=falsepath=/2、使用 profiles.xml 配置了默認(rèn)參數(shù),而在 web 的配置文件中使用到了這些參數(shù),這個(gè)時(shí)候使用命令打包的時(shí)候要指定你要使用哪一個(gè) profilesid 來裝配你的項(xiàng)目,命令如下mvncleanpackage-Pdevelopment,其中-p 是指啟用哪個(gè) profilesid。然后下面部署到 tomcat 的方法和上面的
3、就一樣了使用 maven 的話推薦一個(gè) IDE 工具 IntellijIDEA,他可以直接通過視圖話的方式進(jìn)行指定 profilesid。下面轉(zhuǎn)一篇文章,講 profile 的Profiles 是 maven 的一個(gè)很關(guān)鍵的術(shù)語:profile 是用來定義一些在 buildlifecycle中使用的 environmentalvariations,profile 可以設(shè)置成在不同的環(huán)境下激活不同的profile(例如:不同的 OS 激活不同的 profile,不同的 JVM 激活不同的 profile,不同的dabase 激活不同的 profile 等等)。定義 Profiles你可以把 pr
4、ofiles 定義在 4 個(gè)地方:1、%M2_HOME%/conf/settings.xml,這是針對(duì)該部電腦的所有 user 的 profiles,是globalprofiles,它會(huì)影響所有的 mavenprojectbuild2、 /.m2/settings.xml,這是針對(duì) peruser 的 profiles,是 user 級(jí)的 profiles,它會(huì)影響當(dāng)前 user 的所有mavenprojectbuild3、定義在 pom.xml 文件里面,這是僅針對(duì)該 project 的 profiles,是 project 級(jí)的profiles4、profiles.xml,它和 pom.x
5、ml 在同個(gè)目錄下,也是 project 級(jí)白 pprofiles,使用profiles.xml 的目的是希望把 profiles 的設(shè)置從 pom.xml 里抽離出來設(shè)置。定義在這 4 個(gè)地方的 profiles 中,涉及范圍越窄的 profiles 會(huì)覆蓋范圍越寬的profiles。即:定義在 pom.xml 里 profiles 會(huì)覆蓋 profiles.xml 的,profiles.xml 的會(huì)覆蓋/.m2/settings.xml的,/.m2/settings.xml 的會(huì)覆蓋M2_HOME%/conf/settings.xml 的。不過請(qǐng)注意:設(shè)置在 pom.xml 里的 prof
6、iles 是最最推薦的,因?yàn)?pom.xml 會(huì)被 deploy至 Urepository 里,所以 pom.xml 里的 profiles 才會(huì) availableforsubsequentbuildsoriginatingfromtherepositoryorastransitivedependencies。而 settings.xml和 profiles.xml 里定義的 profiles 不會(huì)被 deploy 至 Urepository,則有諸多限制,因此,只有下面幾個(gè) profiles 能夠在 settings.xml 和 profiles.xml 里定義:repositoriesp
7、luginRepositoriesproperties其他類型的 profiles 必須在 pom.xml 里定義(上面 3 個(gè) profiles 也可以在 pom.xml 里定義)。Pom.xml 能夠定義的 profiles 包括:(notactuallyavailableinthemainPOM,butusedbehindthescenes)asubsetoftheelement,whichconsistsof:2、激活 Profiles激活 profiles 有下列幾種方式:ExplicitlyThroughMavensettingsBasedonenvironmentvariable
8、sOSsettingsPresentormissingfiles1)通過 mvn 命令的-P 參數(shù)來顯示激活 profiles,該參數(shù)值是 profileidlist(之間用逗號(hào)連接)。如:mvngroupId:artifactId:goal-PprofileId-1,profileId-22)通過在 settings.xml 里設(shè)置 element 來激活(當(dāng)然也必須在 settings.xml 里定義)fileprofilesprofile-1activeProfileactiveProfiles.settings列在里的 profilesli
9、st 會(huì)在每一個(gè) project 執(zhí)行時(shí)被激活3)Profiles 還可以基于 detect 至 U 的 buildenvironment 的 state 來自動(dòng)激活,而不需要象上面 2 種方式顯式激活。這只需要在 profile 定義時(shí)使用 element。如:1.4fileprofiles上面的代碼表示:如果 JDKversionstartwith1.4(eg.1.4.0_08,1.4.2_07,1.4),該 profile 會(huì)被激活fileprofiles上面的代碼表示:如果存在 system
10、propertiedebug”,該 profile 會(huì)被激活。為了激活它,輸入的命令類似于:mvngroupId:artifactId:goal-Dfileprofiles上面的代碼表示:如果存在 systempropertieaenvironment的值為 test,該 profile會(huì)被激活。為了激活它,輸入的命令類似于:mvngroupId:artifactId:goal-Denvironment=test4)Profiles 還可以基于 OSsetting 來自動(dòng)激活WindowsXP
11、nameWfileprofiles上面的代碼表示:如果 OS 為 windowsxp,該 profile 會(huì)被激活5)根據(jù)某個(gè) file 不存在而激活 profile。例如下面定義的 profile 是在target/generated-sources/axistools/wsdl2java/org/apache/maven 不存在時(shí)激活target/generated-sources/axistools/wsdl2java/org/apache/mavenmissingfileactivati
12、fileprofiles使用 Profiles 時(shí)要注意的 2 個(gè)問題第一、externalproperties不是定義在 pom.xml 里的 properties 者 B 稱為 externalproperties。舉例說明最明了:pom.xml:.org.myco.pluginsgroupIdspiffy-integrationTest-pluginartifactId1.0version$appserver.homeappserverHject/.m2/settings.xml.appserver
13、Configid/path/to/appserverappserver.homepropertiesprofileprofilesappserverConfigactiveProfileactiveProfiles.settings當(dāng)你執(zhí)行該 pom 時(shí),運(yùn)行正常。但如果 anotheruser 執(zhí)行時(shí),則運(yùn)行失敗,因?yàn)闊o法解析$appserver.home(這是由于該 properties 是定義在 user 級(jí)另1J 的 settings.xml)。解決方法就是把該 profile 放到 pom.xml 里定義,但這樣做的缺點(diǎn)是所有使用該profile 的 pom.xml 每個(gè)都要定義一次
14、該 profile。最好的解決方法是:SinceMavenprovidesgoodsupportforprojectinheritance,itspossibletostickthissortofconfigurationinthepluginManagementsectionofateam-levelPOMorsimilar,andsimplyinheritthepaths第二、pom.xml 里定義的 profiles 不符合激活條件依然是舉個(gè)例子:pom.xml:.appserverConfig-devidenvnamedevvaluepropertyactivation/path/to
15、/dev/appserverappserver.homepropertiesprofileappserverConfig-dev-2idenvnamedev-2valuepropertyactivation/path/to/dev/appserver2appserver.homepropertiesprofileprofilesorg.myco.pluginsgroupIdspiffy-integrationTest-pluginartifactId1.0version$appserver.homeappserverHomeconfigurationplugin.pluginsbuild.pr
16、oject上面定義的 pom.xml 定義了兩個(gè) profile:不同的env參數(shù)值會(huì)激活不同的 profile當(dāng)執(zhí)行命令:mvn-Denv=dev-2integration-test就會(huì)激活 profile“appserverCon 巾 g-dev-2”當(dāng)執(zhí)行命令:mvn-Denv=devintegration-test就會(huì)激活 profile“appserverCon 巾 g-dev”而當(dāng)執(zhí)行命令:mvn-Denv=productionintegration-test則運(yùn)行失敗,因?yàn)闆]有激活任何一個(gè) profile,因此無法解析$appserver.home查看 buildtime 過程中使用了哪些 Profiles執(zhí)行 helpplugin 的 active-profilesgoal,使用命令:mvnhelp:active-profiles例子:對(duì)于上面的例子,如果輸入命令:mvnhelp:active-profiles-Denv=dev則輸出的是:Thefollowingprofilesareactive:-appserverConfig-dev(source:pom)如果有一個(gè) profile 定義在 settings.xml 里并
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 保險(xiǎn)銷售流程培訓(xùn)
- 小學(xué)禁毒安全教育主題班會(huì)記錄
- 職業(yè)病診斷講解
- 集團(tuán)安全培訓(xùn)課件
- 城市污水管網(wǎng)建設(shè)工程申請(qǐng)報(bào)告
- 2025年扎口機(jī)項(xiàng)目建議書
- 五年級(jí)上冊(cè)珍珠鳥教學(xué)設(shè)計(jì)
- 五年級(jí)家鄉(xiāng)的美景500字作文
- 《GBT3367.2-2018內(nèi)燃機(jī)車詞匯第2部分:柴油機(jī)》深度解析
- 城市黑臭水體治理實(shí)施方案中的水環(huán)境治理工程招投標(biāo)研究報(bào)告
- JGJ106-2014 建筑基樁檢測(cè)技術(shù)規(guī)范
- 2023年中國石化河北石家莊石油分公司社會(huì)招聘20人筆試模擬試題及答案解析
- 太陽能熱水系統(tǒng)設(shè)計(jì)
- 醫(yī)務(wù)科崗前培訓(xùn)
- 共青團(tuán)團(tuán)課主題班會(huì)課件PPT模板PPT
- GB/T 8685-2008紡織品維護(hù)標(biāo)簽規(guī)范符號(hào)法
- 合成氨行業(yè)發(fā)展現(xiàn)狀及趨勢(shì)分析
- 2022年徐聞縣(中小學(xué)、幼兒園)教師招聘筆試試題及答案解析
- 網(wǎng)電部管理重點(diǎn)(中)
- 新生兒復(fù)蘇解析課件
- ABI7500熒光定量PCR儀標(biāo)準(zhǔn)操作規(guī)程
評(píng)論
0/150
提交評(píng)論