Myeclipse构建及运行maven web项目

1:环境
Myeclipse 2013,

JDK1.8,

maven 3.3.9,

tomcat7.0.

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

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

2:Myeclipse配置maven

Myeclipse自带maven,单版本较低,需配置下载的高版本maven,配置如下:
window-》prefrences-》maven-》user setting。如图

Myeclipse构建及运行maven web项目_第1张图片

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

Myeclipse构建及运行maven web项目_第2张图片

3:配置tomcat和maven
进入tomcat_home/conf/tomcat_users.xml:修改如下:


    
    
    
    
    
    

 

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


        tomcat
        admin
        admin
    

4:Myeclipse导入maven web项目
Myeclipse构建及运行maven web项目_第3张图片

5:修改pom.xml
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  4.0.0
  com.test
  transition
  war
  0.0.1
  transition Maven Webapp
  http://maven.apache.org
 
      
          maven_remote_1
          http://mirrors.ibiblio.org/pub/mirrors/maven2/
      

 

 
   
      junit
      junit
      3.8.1
      test
   

 

 
    transition
   
        
            org.codehaus.mojo
            tomcat-maven-plugin
            
                target/transition.war
                tomcat
                http://localhost:8080/manager/text
                /transition
              

        

   

 

 

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

Goals项输入:package tomcat:redeploy

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

Myeclipse构建及运行maven web项目_第4张图片

然后点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/。

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

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

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

你可能感兴趣的:(maven)