日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
MavenWeb項(xiàng)目部署到Tomcat

通過Maven來搭建項(xiàng)目是越來越多人的選擇,我也就湊了一下熱鬧,用maven來搭建了項(xiàng)目,發(fā)現(xiàn)還挺好用,但是也遇到了很多問題,下面記錄一下Web項(xiàng)目部署到Tomcat下的問題。

創(chuàng)新互聯(lián)服務(wù)項(xiàng)目包括荔波網(wǎng)站建設(shè)、荔波網(wǎng)站制作、荔波網(wǎng)頁制作以及荔波網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢(shì)、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,荔波網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到荔波省份的部分城市,未來相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!

1、普通的WEB項(xiàng)目,就是雖然是用maven搭建的,但是沒有使用profiles.xml文件來配置參數(shù)。這樣的項(xiàng)目可以通過以下的方式進(jìn)行部署:

直接mvn clean package -DskipTests,進(jìn)行打包,

1) 然后在可以把war包拷到tomcat目錄下的Webapp目錄下

2)修改tomcat目錄下的conf目錄下的server.xml文件,在Host標(biāo)簽之間添加如下一句話:

 
 
 
  1.  

2、使用profiles.xml配置了默認(rèn)參數(shù),而在web的配置文件中使用到了這些參數(shù),這個(gè)時(shí)候使用命令打包的時(shí)候要指定你要使用哪一個(gè)profiles id來裝配你的項(xiàng)目,命令如下mvn clean package -P development ,其中-p是指啟用哪一個(gè)profiles id。然后下面部署到tomcat的方法和上面的就一樣了

使用maven的話推薦一個(gè)IDE工具 Intellij IDEA,他可以直接通過視圖話的方式進(jìn)行指定profiles id。

下面轉(zhuǎn)一篇文章,講profile的

Profiles是maven的一個(gè)很關(guān)鍵的術(shù)語:profile是用來定義一些在build lifecycle中使用的environmental variations,profile可以設(shè)置成在不同的環(huán)境下激活不同的profile(例如:不同的OS激活不同的profile,不同的JVM激活不同的profile,不同的dabase激活不同的profile等等)。

定義Profiles

你可以把profiles定義在4個(gè)地方:

1、%M2_HOME%/conf/settings.xml,這是針對(duì)該部電腦的所有user的profiles,是global profiles,它會(huì)影響所有的maven project build

2、/.m2/settings.xml,這是針對(duì)per user的profiles,是user級(jí)的profiles,它會(huì)影響當(dāng)前user的所有maven project build

3、定義在pom.xml文件里面,這是僅針對(duì)該project的profiles,是project級(jí)的profiles

4、profiles.xml,它和pom.xml在同一個(gè)目錄下,也是project級(jí)的profiles,使用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里的profiles是最最推薦的,因?yàn)閜om.xml會(huì)被deploy到repository里,所以pom.xml里的profiles才會(huì)available for subsequent builds originating from the repository or as transitive dependencies。而settings.xml和profiles.xml里定義的profiles不會(huì)被deploy到repository,則有諸多限制,因此,只有下面幾個(gè)profiles能夠在settings.xml和profiles.xml里定義:

repositories

pluginRepositories

properties 

其他類型的profiles必須在pom.xml里定義(上面3個(gè)profiles也可以在pom.xml里定義)。

Pom.xml能夠定義的profiles包括:

 
 
 
  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  (not actually available in the main POM, but used behind the scenes)  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19. a subset of the  element, which consists of:  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  

2、激活Profiles

激活profiles有下列幾種方式:

Explicitly

Through Maven settings

Based on environment variables

OS settings

Present or missing files

1)通過mvn命令的-P參數(shù)來顯示激活profiles,該參數(shù)值是profile id list(之間用逗號(hào)連接)。如:

 
 
 
  1. mvn groupId:artifactId:goal -P profileId-1,profileId-2 

2) 通過在settings.xml里設(shè)置 element來激活(當(dāng)然也必須在settings.xml里定義)

 
 
 
  1.  
  2. ...  
  3.  
  4.  
  5. profile1 
  6. ...  
  7.  
  8.  
  9.  
  10. profile-1 
  11.  
  12. ...  
  13.  

列在里的profiles list會(huì)在每一個(gè)project執(zhí)行時(shí)被激活

3)Profiles還可以基于detect到的build environment 的state來自動(dòng)激活,而不需要象上面2種方式顯式激活。這只需要在profile定義時(shí)使用 element。如:

 
 
 
  1.  
  2.  
  3.  
  4. 1.4 
  5.  
  6. ...  
  7.  
  8.  

上面的代碼表示:如果JDK version start with 1.4 (eg. "1.4.0_08", "1.4.2_07", "1.4"),該profile會(huì)被激活

 
 
 
  1.  
  2.  
  3.  
  4.  
  5. debug 
  6.  
  7.  
  8. ...  
  9.  
  10.  

上面的代碼表示:如果存在system propertie “debug”,該profile會(huì)被激活。為了激活它,輸入的命令類似于:

 
 
 
  1. mvn groupId:artifactId:goal –Ddebug 
 
 
 
  1.  
  2.  
  3.  
  4.  
  5. environment 
  6. test 
  7.  
  8.  
  9. ...  
  10.  
  11.  

上面的代碼表示:如果存在system propertie “environment”的值為test,該profile會(huì)被激活。為了激活它,輸入的命令類似于:

 
 
 
  1. mvn groupId:artifactId:goal -Denvironment=test 

4)Profiles還可以基于OS setting來自動(dòng)激活

 
 
 
  1.  
  2.  
  3.  
  4.  
  5. Windows XP 
  6. Windows 
  7. x86 
  8. 5.1.2600 
  9.  
  10.  
  11. ...  
  12.  
  13.  

上面的代碼表示:如果OS為windows xp,該profile會(huì)被激活

5)根據(jù)某個(gè)file不存在而激活profile。例如下面定義的profile是在target/generated-sources/axistools/wsdl2java/org/apache/maven不存在時(shí)激活

 
 
 
  1.  
  2.  
  3.  
  4.  
  5. target/generated-sources/axistools/wsdl2java/org/apache/maven 
  6.  
  7.  
  8. ...  
  9.  
  10.  

使用Profiles時(shí)要注意的2個(gè)問題

第一、external properties

不是定義在pom.xml里的properties都稱為external properties。舉例說明最明了:

pom.xml:

 
 
 
  1.  
  2. ...  
  3.  
  4.  
  5.  
  6. org.myco.plugins 
  7. spiffy-integrationTest-plugin 
  8. 1.0 
  9.  
  10. ${appserver.home} 
  11.  
  12.  
  13. ...  
  14.  
  15.  
  16. ...  
  17.  

~/.m2/settings.xml

 
 
 
  1.  
  2. ...  
  3.  
  4.  
  5. appserverConfig 
  6.  
  7. /path/to/appserver 
  8.  
  9.  
  10.  
  11.  
  12. appserverConfig 
  13.  
  14. ...  
  15.  

當(dāng)你執(zhí)行該pom時(shí),運(yùn)行正常。但如果another user執(zhí)行時(shí),則運(yùn)行失敗,因?yàn)闊o法解析${appserver.home}(這是由于該properties是定義在user級(jí)別的settings.xml)。

解決方法就是把該profile放到pom.xml里定義,但這樣做的缺點(diǎn)是所有使用該profile的pom.xml每個(gè)都要定義一次該profile。

最好的解決方法是:Since Maven provides good support for project inheritance, it's possible to stick this sort of configuration in the pluginManagement section of a team-level POM or similar, and simply inherit the paths

第二、pom.xml里定義的profiles不符合激活條件

依然是舉個(gè)例子:

pom.xml:

 
 
 
  1.  
  2. ...  
  3.  
  4.  
  5. appserverConfig-dev 
  6.  
  7.  
  8. env 
  9. dev 
  10.  
  11.  
  12.  
  13. /path/to/dev/appserver 
  14.  
  15.  
  16.  
  17. appserverConfig-dev-2 
  18.  
  19.  
  20. env 
  21. dev-2 
  22.  
  23.  
  24.  
  25. /path/to/dev/appserver2 
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32. org.myco.plugins 
  33. spiffy-integrationTest-plugin 
  34. 1.0 
  35.  
  36. ${appserver.home} 
  37.  
  38.  
  39. ...  
  40.  
  41.  
  42. ...  
  43.  

上面定義的pom.xml定義了兩個(gè)profile:不同的”env”參數(shù)值會(huì)激活不同的profile。當(dāng)執(zhí)行命令:

 
 
 
  1. mvn -Denv=dev-2 integration-test 

就會(huì)激活profile “appserverConfig-dev-2”

當(dāng)執(zhí)行命令:

 
 
 
  1. mvn -Denv=dev integration-test 

就會(huì)激活profile “appserverConfig-dev”

而當(dāng)執(zhí)行命令:

 
 
 
  1. mvn -Denv=production integration-test 

則運(yùn)行失敗,因?yàn)闆]有激活任何一個(gè)profile,因此無法解析${appserver.home}。

查看build time過程中使用了哪些Profiles

執(zhí)行help plugin的active-profiles goal,使用命令:

 
 
 
  1. mvn help:active-profiles 

例子:

對(duì)于上面的例子,如果輸入命令:

 
 
 
  1. mvn help:active-profiles -Denv=dev 

則輸出的是:

 
 
 
  1. The following profiles are active:  
  2. - appserverConfig-dev (source: pom) 

如果有一個(gè)profile定義在settings.xml里并使用激活,那么輸入命令:

 
 
 
  1. mvn help:active-profiles 

則輸出的是:

 
 
 
  1. The following profiles are active: 
  2. - appserverConfig (source: settings.xml)

如果輸入命令:

 
 
 
  1. mvn help:active-profiles -P appserverConfig-dev 

那么輸出的是:

 
 
 
  1. The following profiles are active:  
  2. - appserverConfig-dev (source: pom)  
  3. - appserverConfig (source: settings.xml) 

原文鏈接:http://wcp88888888.iteye.com/blog/1330692


本文標(biāo)題:MavenWeb項(xiàng)目部署到Tomcat
網(wǎng)址分享:http://www.5511xx.com/article/cohpigc.html