eclipse构建及运行maven web项目

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,控制台显示如下:

 
[INFO] Processing war project

[INFO] Copying webapp resources [E:\transition\src\main\webapp]

[INFO] Webapp assembled in [3 msecs]

[INFO] Building war: E:\transition\target\transition.war

[INFO] WEB-INF\web.xml already added, skipping

[INFO]

[INFO] <<< tomcat-maven-plugin:1.1:redeploy (default-cli) @ transition <<<

[INFO]

[INFO] --- tomcat-maven-plugin:1.1:redeploy (default-cli) @ transition ---

[INFO] Deploying war to http://localhost:8080/transition

[INFO] OK - Undeployed application at context path /transition

[INFO] OK - Deployed application at context path /transition

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

[INFO] BUILD SUCCESS

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

[INFO] Total time: 2.412 s

[INFO] Finished at: 2014-03-13T11:43:42+08:00

[INFO] Final Memory: 6M/15M

[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。

       

 

最近整理出了有关大数据,微服务,分布式,Java,Python,Web前端,产品运营,交互等1.7G的学习资料,有视频教程,源码,课件,软件工具,面试题等等,这里将珍藏多年的资源免费分享给各位小伙伴们。

领取方式:https://blog.csdn.net/qq_42914528/article/details/81777449                                      

                                                         

欢迎大家关注我的公众号:

里面会分享很多JAVA技术、新知识、新技术、面试宝典等。
有让技术爱好者(程序猿)得到很大提升的文章资料。

还在犹豫什么,赶紧关注一波,微信搜索公众号:程序员的成长之路。或者扫描下方二维码进行关注。

                                                                     

                                                                       欢迎关注公众号,和我一起成长!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值