http://blog.youkuaiyun.com/maosijunzi/article/details/21160965
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:修改如下:
进入maven_home/conf/settings.xml:修改如下:
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
8:运行maven项目
先进入tomcat目录启动tomcat,然后右键项目 run as-》run configrations:
Goals项输入:package tomcat:redeploy
Maven Runtime选择我们自己的maven。如图:
然后点Run,控制台显示如下:
这里省略很多控制台输出,出现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。
创建完成后pom文件报错
-
eclipse创建maven项目后报错,急~10
Description Resource Path Location Type
Could not calculate build plan: Failure to transfer org.apache.maven.plugins:maven-war-plugin:pom:2.1.1 from http://repo1.maven.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact org.apache.maven.plugins:maven-war-plugin:pom:2.1.1 from/to central (http://repo1.maven.org/maven2): ConnectException first-maven Unknown Maven Problem
2011年3月26日 15:18src="http://www.iteye.com/iframe_ggbd/186" scrolling="no" width="468" height="60" frameborder="0">
1个答案按时间排序按投票排序
-
应该是连不上http://repo1.maven.org/maven2这个仓库,在你的pom.xml文件加一下下面的配置试试看。
- <repositories>
- <repository>
- <snapshots>
- <enabled>false</enabled>
- </snapshots>
- <id>central</id>
- <name>Maven Repository Switchboard</name>
- <url>http://repo2.maven.org/maven2</url>
- </repository>
- </repositories>
-
eclipse创建maven项目后报错,急~10
Description Resource Path Location Type
Could not calculate build plan: Failure to transfer org.apache.maven.plugins:maven-war-plugin:pom:2.1.1 from http://repo1.maven.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact org.apache.maven.plugins:maven-war-plugin:pom:2.1.1 from/to central (http://repo1.maven.org/maven2): ConnectException first-maven Unknown Maven Problem
2011年3月26日 15:18src="http://www.iteye.com/iframe_ggbd/186" scrolling="no" width="468" height="60" frameborder="0">