1:环境

eclipse indigo,

JDK1.6,

maven 3.2.1,

tomcat7.0.42

2:安装eclipse maven插件 m2eclipse

第一种方法:从网上下载m2eclipse,这个网上有很多下载的地方。然后放到eclipse安装目录的plugins下。

第二种方法:打开eclipse->help->install new software。在work with后输入:http://download.eclipse.org/technology/m2e/releases。如图:

3:下载maven和tomcat

上apache官网下载maven:http://maven.apache.org/download.cgi。下载完成后解压即可。

上apache官网下载tomcat:http://tomcat.apache.org/

4:eclipse配置maven

window-》prefrences-》maven-》user setting。如图

window-》prefrences-》maven-》installations。如图

5:配置tomcat和maven

进入tomcat_home/conf/tomcat_users.xml:修改如下:

  1. <role rolename="admin-gui"/>
  2. <role rolename="admin-script"/>
  3. <role rolename="manager-gui"/>
  4. <role rolename="manager-script"/>
  5. <role rolename="manager-jmx"/>
  6. <role rolename="manager-status"/>
  7. <user username="admin" password="admin" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-script,admin-gui"/>
 

进入maven_home/conf/settings.xml:修改如下:

  1. <server>
  2. <id>tomcat</id>
  3. <username>admin</username>
  4. <password>admin</password>
  5. </server>

6:eclipse创建maven web项目

这个简单,new-》other-》maven project-》next。这里注意groupid选org.apache.maven.archetypes ,artifactid 选maven-archetype-webapp,然后next,输入我们自己的groupid(com.test),artifactid(transition),然后finish,OK。如图所示:

7:修改pom.xml

  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  3. <modelVersion>4.0.0</modelVersion>
  4. <groupId>com.test</groupId>
  5. <artifactId>transition</artifactId>
  6. <packaging>war</packaging>
  7. <version>0.0.1</version>
  8. <name>transition Maven Webapp</name>
  9. <url>http://maven.apache.org</url>
  10. <repositories>
  11. <repository>
  12. <id>maven_remote_1</id>
  13. <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
  14. </repository>
  15. </repositories>
  16. <dependencies>
  17. <dependency>
  18. <groupId>junit</groupId>
  19. <artifactId>junit</artifactId>
  20. <version>3.8.1</version>
  21. <scope>test</scope>
  22. </dependency>
  23. </dependencies>
  24. <build>
  25. <finalName>transition</finalName>
  26. <plugins>
  27. <plugin>
  28. <groupId>org.codehaus.mojo</groupId>
  29. <artifactId>tomcat-maven-plugin</artifactId>
  30. <configuration>
  31. <warFile>target/transition.war</warFile>
  32. <server>tomcat</server>
  33. <url>http://localhost:8080/manager/text</url>
  34. <path>/transition</path>
  35. </configuration>
  36. </plugin>
  37. </plugins>
  38. </build>
  39. </project>

8:运行maven项目

先进入tomcat目录启动tomcat,然后右键项目 run as-》run configrations:

Goals项输入:package tomcat:redeploy

Maven Runtime选择我们自己的maven。如图:

然后点Run,控制台显示如下:

  1. [INFO] Processing war project
  2. [INFO] Copying webapp resources [E:\transition\src\main\webapp]
  3. [INFO] Webapp assembled in [3 msecs]
  4. [INFO] Building war: E:\transition\target\transition.war
  5. [INFO] WEB-INF\web.xml already added, skipping
  6. [INFO]
  7. [INFO] <<< tomcat-maven-plugin:1.1:redeploy (default-cli) @ transition <<<
  8. [INFO]
  9. [INFO] --- tomcat-maven-plugin:1.1:redeploy (default-cli) @ transition ---
  10. [INFO] Deploying war to http://localhost:8080/transition
  11. [INFO] OK - Undeployed application at context path /transition
  12. [INFO] OK - Deployed application at context path /transition
  13. [INFO] ------------------------------------------------------------------------
  14. [INFO] BUILD SUCCESS
  15. [INFO] ------------------------------------------------------------------------
  16. [INFO] Total time: 2.412 s
  17. [INFO] Finished at: 2014-03-13T11:43:42+08:00
  18. [INFO] Final Memory: 6M/15M
  19. [INFO] ------------------------------------------------------------------------

这里省略很多控制台输出,出现BUILD SUCCESS 则说明部署成功,浏览器输入:http://localhost:8080/transition/。显示Hello world..

注意:这样成功之后项目会直接打成war包,部署到tomcat下,每次build不需要重启tomcat。这样致命的缺点就是,不能调试。如果需要调试且在eclipse中启动tomcat的话。会发现右键项目没有run as server,有两种方法解决:

第一种:这时需要把项目转变成dynamic web module。右键项目-》properties-》project facets,然后右边选中dynamic web module。之后就会出现run as  server了.

第二种:右键项目,run/debug  as  configrations  如上第8步骤的图。不过Goals中天上【tomcat:run】。然后run就OK了,注意这里不需要提前启动tomcat。

eclipse构建及运行maven web项目的更多相关文章

  1. eclipse 创建并运行maven web项目

    这两天想在eclipse上运行maven web项目,折腾了许久,总算success啦. 1,利用eclipse创建dynamic web project(eclipse需要安装m2eclipse). ...

  2. 使用eclipse运行maven web项目 插件/非插件

    一.使用插件 tomcat 8.5 tomcat-users.xml中添加这一行就ok <user username="admin" password="admin ...

  3. Maven学习篇一:eclipse构建运行maven web项目

    1.new->other->maven project->next 2.选择创建简单项目(或者直接去掉勾,在后面选择maven-archetype-webapp) 3.设置坐标,名称 ...

  4. eclipse 和 Myeclipse中Maven Web项目出现小红叉的 详细解决方法

    在我们创建maven项目是常会出现小红叉,如图: 解决办法: 1.可以 点击鼠标右键  maven--->update project.一般可以解决. 2.查看 window---->sh ...

  5. maven 学习---用Eclipse创建一个Maven Web项目

    下面是使用 Eclipse 来创建一个Maven Web项目的说明.这是相当简单的. 现在让我们开始吧! 1: 启动 Eclipse, 点击 File->New->Other 2: 在弹出 ...

  6. Eclipse中导入Maven Web项目并配置其在Tomcat中运行

    今天因为实习的关系需要讲公司已经开发的项目导入进Eclipse,而公司的项目是用Maven来构建的所以,需要将Maven项目导入进Eclipse下. 自己因为没有什么经验所以搞了得两个多小时,在这里和 ...

  7. Eclipse创建一个Maven Web项目

    在这篇文章中,我们将演示如何在Eclipse IDE中使用maven创建一个动态Web项目. 使用的工具和技术 - Eclipse Jee Oxygen Maven 3.3.3 JavaSE 1.8 ...

  8. myeclipse下构建maven web项目

    首先创建一个Maven的Project如下图 我们勾选上Create a simple project (不使用骨架) 这里的Packing 选择 war的形式 由于packing是war包,那么下面 ...

  9. Eclipse 搭建 Maven Web项目

    第一步:安装JDK: 第二步:安装Eclipse: 第三步:安装tomcat7: 第四步:安装maven插件: 4.1 下载maven:http://maven.apache.org/download ...

随机推荐

  1. MongoDB学习笔记二:创建、更新及删除文档

    插入并保存文档 对目标集使用insert方法插入一个文档: > db.foo.insert({"bar" : "baz"}) 这个操作会给文档增加一个&q ...

  2. Android项目的目录结构

    assets  资产目录,  存放一个文件的 这个文件会被打包到应用程序的apk(安装包 ) bin 编译后的文件目录 gen 自动生成文件的目录 roject.properties 代表编译的版本  ...

  3. 数迹学——Asp.Net MVC4入门指南(4):添加一个模型

    一.添加模型类 二.添加MovieDBContext类,连接数据库 DbContext类继承自 System.Data.Entity; 负责在数据库中获取,存储,更新,处理实例 MovieDBCont ...

  4. 39:第n小的质数

    39:第n小的质数    总时间限制:    1000ms    内存限制:    65536kB描述    输入一个正整数n,求第n小的质数.输入    一个不超过10000的正整数n.输出    ...

  5. IIS:开启GZIP压缩效率对比及部署方法

    HTTP压缩 HTTP压缩是在Web服务器和浏览器间传输压缩文本内容的方法.HTTP压缩采用通用的压缩算法如GZIP等压缩HTML.JavaScript或CSS文件.压缩的最大好处就是降低了网络传输的 ...

  6. maya,mel,eval,stringarray

    mel里,当要eval("client()"),并且要传递stirngarray参数给函数client()时,正确的写法应该是: global proc intermediator ...

  7. UITapGestureRecognizer响应顺序是怎么样的

    一个scrollview上有几个按钮在scrollview上add 了一个单击事件 singletap = [[UITapGestureRecognizer alloc] initWithTarget ...

  8. 类似新浪 腾讯微博字数统计 控制js(区分中英文 符号)

    <script> ; function Q(s) { return document.getElementById(s); } function checkWord(c) { len = ...

  9. javascript 自调用函数 闭包

    <script type="text/javascript"> var car = {name:"lhs",model:500}; window.o ...

  10. iScroll滚动区域中select、input、textarea元素无法点击的Bug修复

    最近在一个项目中使用了iScroll4模拟滚动效果,调试过程中发现一个表单页中的所有表单项都无法点击聚焦, 如<select>.<input>.<textarea> ...