Maven多模組開發之Web工程調試與布署

來源:互聯網
上載者:User

最近學習在eclipse3.6環境下用maven2構建一個多模組的項目

分core/dal/dao/web四塊,當運行tomcat web工程調試需要把core/dal/dao的工程先mvn install一下,才能提交更新,反覆折騰以後總結出幾條很有用的訊息,希望和我一樣剛接觸maven的朋友不要再走錯路.在百度和google查了好幾天也沒有完整的資料,最後還是自己想到辦法了.

方法一:

tomcat

  1. 首先將maven web工程轉為eclipse wtp工程(網上搜一下),一般說來到maven工程目錄下執行命令列mvn eclipse:eclipse -Dwtpversion=2.0即可.
  2. 將工程添加到tomcat server中
  3. 添加其它工程的引用
  4. 因為tomcat外掛程式publish的內容是src/main裡的,所以web-inf/lib的外部包需要手動拷到外掛程式啟動並執行目錄,外掛程式運行目錄我的是在D:/EclipseWorkspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp/wtpwebapps/my-web
  5. 運行tomcat,在其它dao等工程做的修改,tomcat會自動reload了.

 

方法二.jetty

鑒於第一種方式需要手動拷jar的,我可受不了.於是最終選擇jetty外掛程式,就目前來看是用得最爽的.

1.在pom.xml加入jetty外掛程式資訊

<build><br /> <finalName>myweb</finalName><br /> <plugins><br /> <plugin><br /> <groupId>org.mortbay.jetty</groupId><br /> <artifactId>maven-jetty-plugin</artifactId><br /> <version>6.1.12</version><br /> <configuration><br /> <!-- 熱載入掃描間隔秒數 --><br /> <scanIntervalSeconds>5</scanIntervalSeconds><br /> <stopKey>/</stopKey><br /> <stopPort>9999</stopPort><br /> <!-- 額外掃描的class路徑 --><br /> <scanTargets><br /><scanTarget>D:/EclipseWorkspace/myweb/myweb-dal/target/classes</scanTarget><br /><scanTarget>D:/EclipseWorkspace/myweb/myweb-core/target/classes</scanTarget><br /></scanTargets><br /> <webAppConfig><br />            <contextPath>/</contextPath><br /><!-- jetty設定檔 --><br /> <defaultsDescriptor>src/main/resources/webdefault.xml</defaultsDescriptor><br /> <!-- 引用其它工程的class --><br />             <extraClasspath>D:/EclipseWorkspace/myweb/myweb-core/target/classes;D:/EclipseWorkspace/myweb/myweb-dal/target/classes</extraClasspath></p><p>          </webAppConfig><br /> </configuration><br /></plugin><br /> </plugins><br /> </build>

2.配置eclipse run configurations

 

 

 

 

 

在goals中填寫jetty:run -e -q

run as -> Maven build就可以運行web工程以及布署和調試,最大的好處,修改無需重啟jetty.

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.