Maven構建web項目在Eclipse中部署的幾種方法


Maven構建web項目在Eclipse中部署的幾種方法

做者: Michael 日期: 2012 年 9 月 10 日 發表評論 (3)查看評論java

目錄:web

  • 方法一:運用Maven的plugin:jetty來部署web瀏覽器

  • 方法二:運用Eclipse 的Jetty插件直接部署tomcat

  • 方法三:運用Run on Server(tomcat)部署app

[方法一]、運用Maven的plugin:jetty來部署eclipse

第一步:配置POM.xml 文件webapp

在節點<build><plugins>…</plugins></build>中配置Jetty插件依賴以下:maven

XHTMLide

<plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>maven-jetty-plugin</artifactId> <version>6.1.26</version> <configuration> <webAppSourceDirectory>${basedir}/src/main/webapp</webAppSourceDirectory> </configuration> </plugin>ui

1

2

3

4

5

6

7

8

<plugin>

<groupId>org.mortbay.jetty</groupId>

<artifactId>maven-jetty-plugin</artifactId>

<version>6.1.26</version>

<configuration>

<webAppSourceDirectory>${basedir}/src/main/webapp</webAppSourceDirectory>

</configuration>

</plugin>

第二步:配置goals參數

右擊項目 –> Run As –> Maven Build… –> Goals  輸入:jetty:run 便可:

點擊Run按鈕即運行日誌信息以下:

[INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building myweb Maven Webapp 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] &gt;&gt;&gt; maven-jetty-plugin:6.1.26:run (default-cli) @ myweb &gt;&gt;&gt; [INFO] [INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ myweb --- [debug] execute contextualize [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] Copying 0 resource [INFO] [INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ myweb --- [INFO] No sources to compile [INFO] [INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ myweb --- [debug] execute contextualize [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory D:\workspace_sun\maven-demo\myweb\src\test\resources [INFO] [INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ myweb --- [INFO] No sources to compile [INFO] [INFO] &lt;&lt;&lt; maven-jetty-plugin:6.1.26:run (default-cli) @ myweb &lt;&lt;&lt; [INFO] [INFO] --- maven-jetty-plugin:6.1.26:run (default-cli) @ myweb --- [INFO] Configuring Jetty for project: myweb Maven Webapp [INFO] Webapp source directory = D:\workspace_sun\maven-demo\myweb\src\main\webapp [INFO] Reload Mechanic: automatic [INFO] Classes = D:\workspace_sun\maven-demo\myweb\target\classes 2012-09-10 16:06:55.837:INFO::Logging to STDERR via org.mortbay.log.StdErrLog [INFO] Context path = /myweb [INFO] Tmp directory =  determined at runtime [INFO] Web defaults = org/mortbay/jetty/webapp/webdefault.xml [INFO] Web overrides =  none [INFO] web.xml file = D:\workspace_sun\maven-demo\myweb\src\main\webapp\WEB-INF\web.xml [INFO] Webapp directory = D:\workspace_sun\maven-demo\myweb\src\main\webapp [INFO] Starting jetty 6.1.26 ... 2012-09-10 16:06:55.945:INFO::jetty-6.1.26 2012-09-10 16:06:56.082:INFO::No Transaction manager found - if your webapp requires one, please configure one. [INFO] Started Jetty Server 2012-09-10 16:06:56.382:INFO::Started SelectChannelConnector@0.0.0.0:8080

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

[INFO] Scanning for projects...

[INFO]

[INFO] ------------------------------------------------------------------------

[INFO] Building myweb Maven Webapp 0.0.1-SNAPSHOT

[INFO] ------------------------------------------------------------------------

[INFO]

[INFO] &gt;&gt;&gt; maven-jetty-plugin:6.1.26:run (default-cli) @ myweb &gt;&gt;&gt;

[INFO]

[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ myweb ---

[debug] execute contextualize

[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!

[INFO] Copying 0 resource

[INFO]

[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ myweb ---

[INFO] No sources to compile

[INFO]

[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ myweb ---

[debug] execute contextualize

[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!

[INFO] skip non existing resourceDirectory D:\workspace_sun\maven-demo\myweb\src\test\resources

[INFO]

[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ myweb ---

[INFO] No sources to compile

[INFO]

[INFO] &lt;&lt;&lt; maven-jetty-plugin:6.1.26:run (default-cli) @ myweb &lt;&lt;&lt;

[INFO]

[INFO] --- maven-jetty-plugin:6.1.26:run (default-cli) @ myweb ---

[INFO] Configuring Jetty for project: myweb Maven Webapp

[INFO] Webapp source directory = D:\workspace_sun\maven-demo\myweb\src\main\webapp

[INFO] Reload Mechanic: automatic

[INFO] Classes = D:\workspace_sun\maven-demo\myweb\target\classes

2012-09-10 16:06:55.837:INFO::Logging to STDERR via org.mortbay.log.StdErrLog

[INFO] Context path = /myweb

[INFO] Tmp directory =  determined at runtime

[INFO] Web defaults = org/mortbay/jetty/webapp/webdefault.xml

[INFO] Web overrides =  none

[INFO] web.xml file = D:\workspace_sun\maven-demo\myweb\src\main\webapp\WEB-INF\web.xml

[INFO] Webapp directory = D:\workspace_sun\maven-demo\myweb\src\main\webapp

[INFO] Starting jetty 6.1.26 ...

2012-09-10 16:06:55.945:INFO::jetty-6.1.26

2012-09-10 16:06:56.082:INFO::No Transaction manager found - if your webapp requires one, please configure one.

[INFO] Started Jetty Server

2012-09-10 16:06:56.382:INFO::Started SelectChannelConnector@0.0.0.0:8080

打開瀏覽器輸入:http://localhost:8080/myweb/ 便可驗證web項目是否啓動正常。

[方法二]、運用Eclipse 的Jetty插件直接部署

第一步:首先安裝Eclipse Jetty插件

插件地址:http://code.google.com/p/run-jetty-run/

第二步:直接右擊項目 –> Run As –> Run Jetty

運行日誌信息以下:

Running Jetty 6.1.26 2012-09-10 16:28:13.308:INFO::Logging to STDERR via org.mortbay.log.StdErrLog ParentLoaderPriority enabled Context path:/myweb ProjectClassLoader: entry=D:\workspace_sun\maven-demo\myweb\target\classes ProjectClassLoader: entry=D:\.m2\repository\junit\junit\3.8.1\junit-3.8.1.jar 2012-09-10 16:28:13.374:INFO::jetty-6.1.26 2012-09-10 16:28:13.697:INFO::Started SelectChannelConnector@0.0.0.0:8080

1

2

3

4

5

6

7

8

Running Jetty 6.1.26

2012-09-10 16:28:13.308:INFO::Logging to STDERR via org.mortbay.log.StdErrLog

ParentLoaderPriority enabled

Context path:/myweb

ProjectClassLoader: entry=D:\workspace_sun\maven-demo\myweb\target\classes

ProjectClassLoader: entry=D:\.m2\repository\junit\junit\3.8.1\junit-3.8.1.jar

2012-09-10 16:28:13.374:INFO::jetty-6.1.26

2012-09-10 16:28:13.697:INFO::Started SelectChannelConnector@0.0.0.0:8080

一樣打開瀏覽器輸入:http://localhost:8080/myweb/ 便可驗證web項目是否啓動正常。

[方法三]、運用Run on Server(tomcat)部署

第一步:轉爲Eclipse web項目

Maven web 項目轉爲Eclipse web項目的基本命令:

mvn eclipse:eclipse -Dwtpverison=1.0

1

mvn eclipse:eclipse -Dwtpverison=1.0

而後把轉化後的項目導入到Eclipse中

第二步:配置web項目Maven lib依賴關係

詳見:http://www.micmiu.com/software/build/eclipse-maven-web-lib/

第三步:和之前web項目同樣,添加到Server中運行便可

一樣打開瀏覽器輸入:http://localhost:8080/myweb/ 便可驗證web項目是否啓動正常。

本文介紹到此結束@Michael Sun.

相關文章
相關標籤/搜索