cundeng 发表于 2017-2-28 07:20:22

Maven构建web项目在Eclipse中部署的几种方法

目录:


[*]方法一:运用Maven的plugin:jetty来部署web
[*]方法二:运用Eclipse 的Jetty插件直接部署
[*]方法三:运用Run on Server(tomcat)部署
  [方法一]、运用Maven的plugin:jetty来部署
  第一步:配置POM.xml 文件
  在节点<build><plugins>…</plugins></build>中配置Jetty插件依赖如下:








XHTML



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按钮即运行日志信息如下:






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

Scanning for projects...

------------------------------------------------------------------------
Building myweb Maven Webapp 0.0.1-SNAPSHOT
------------------------------------------------------------------------

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

--- maven-resources-plugin:2.5:resources (default-resources) @ myweb ---
execute contextualize
Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
Copying 0 resource

--- maven-compiler-plugin:2.3.2:compile (default-compile) @ myweb ---
No sources to compile

--- maven-resources-plugin:2.5:testResources (default-testResources) @ myweb ---
execute contextualize
Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
skip non existing resourceDirectory D:\workspace_sun\maven-demo\myweb\src\test\resources

--- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ myweb ---
No sources to compile

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

--- maven-jetty-plugin:6.1.26:run (default-cli) @ myweb ---
Configuring Jetty for project: myweb Maven Webapp
Webapp source directory = D:\workspace_sun\maven-demo\myweb\src\main\webapp
Reload Mechanic: automatic
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
Context path = /myweb
Tmp directory =determined at runtime
Web defaults = org/mortbay/jetty/webapp/webdefault.xml
Web overrides =none
web.xml file = D:\workspace_sun\maven-demo\myweb\src\main\webapp\WEB-INF\web.xml
Webapp directory = D:\workspace_sun\maven-demo\myweb\src\main\webapp
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.
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

  运行日志信息如下:






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项目的基本命令:






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.
  http://www.micmiu.com/software/build/maven-web-eclipse-deploy/
页: [1]
查看完整版本: Maven构建web项目在Eclipse中部署的几种方法