原文地址: http://www.blogjava.net/sealyu/archive/2010/01/08/308706.html

Procedure

Prerequisites and Assumptions

  • Maven is already installed
  • A local instance of Tomcat is already installed and configured to run on port 8080
  • Optional - Eclipse is installed

Step One - Prepare the Tomcat Manager application

In order to deploy a web app to your Tomcat server, you will need to ensure that you can access the Tomcat Manager application at:http://localhost:8080/manager/html. Typically, you just need to ensure that your <tomcat>/conf/tomcat-users.xml file has the following defined:

<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
  <role rolename="manager"/>
  <role rolename="admin"/>
  <user username="admin" password="admin" roles="admin,manager"/>
</tomcat-users>

In this case, we will be logging in to the Tomcat Manager app using:

username admin
password admin

Back to Top


Step Two - Create a New Web App Using Maven

Next, we will use a Maven archetype to generate a new web application project.

Assuming that you will primarily use Eclipse as your IDE, you may wish to start the project within Eclipse. We'll start the project within Eclipse and then use Maven to fill the project in with the proper Maven web app structure.

  • In Eclipse create a new General project. New > Project... > General > Project
  • Project name: "sw" (name it what you wish, but remember to replace 'sw' with your project name in all instances where that appears in this document from here on out.)

The steps above just create a General project in your Eclipse workspace (e.g. a folder with a .project settings file inside of it).

Next, open a command prompt, cd into the 'sw' project directory, and then execute the following Maven command (all on one line):

mvn archetype:create
   -DgroupId=com.burlesontech.sw
   -DartifactId=webapp
   -DarchetypeArtifactId=maven-archetype-webapp

You project will now have the following structure:

  • sw

    • webapp

      • src

        • main

          • resources
          • webapp
            • WEB-INF

              • web.xml
            • index.jsp
      • pom.xml
    • .project

In Eclipse, right-click on the project and select Refresh to see this stuff within Eclipse. (Note that the .project file will typically not appear within Eclipse, but it is there.)

Back to Top


Step Three - Define Your Tomcat Server in Maven Settings

Open your Maven settings.xml file (e.g. C:"Documents and Settings"Administrator".m2"settings.xml) and add a server 'myserver' with the credentials for logging into the Tomcat Manager application:

<settings>
    <servers>
    <server>
        <id>myserver</id>
        <username>admin</username>
        <password>admin</password>
    </server>
    </servers>
...

Back to Top


Step Four - Point Your Pom to Your Tomcat Server

Open the pom.xml file in the 'sw' project and replace the <build> section so that it looks like this:

<build>
    <finalName>sw</finalName>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>tomcat-maven-plugin</artifactId>
            <configuration>
                     <server>myserver</server>
                     <path>/sw</path>
            </configuration>
        </plugin>
    </plugins>
</build>

Here, we have added the Tomcat plugin for Maven. Note that the <configuration> section needs to point to the server you defined in settings.xml ('myserver'). The <finalName> and the <path> are used to tell the web context that you want to deploy to. In this case, we'll be able to access our application athttp://localhost:8080/sw.

Back to Top


Step Five - Build and Deploy the Web App

On a command prompt, you can now cd into the sw/webapp directory where the project pom exists. The execute the following command:

mvn tomcat:deploy

If you get a BUILD SUCCESSFUL message, you should then be able to access your web application at http://localhost:8080/sw/.

You should see "Hello World!" in your web browser (from the index.jsp page). Now you're all set and ready to start building the next killer web app!

If you try to deploy again with the same command, you will likely get a FAIL message because the application already exists at the path. For successive deployments, use the following command instead:

mvn tomcat:redeploy

Next, you may want to enable log4j logging for your new application; check out How to setup Log4j in a web app - fast.

How to create a Maven web app and deploy to Tomcat - fast的更多相关文章

  1. JavaEE开发基于Eclipse的环境搭建以及Maven Web App的创建

    本篇博客就完整的来聊一下如何在Eclipse中创建的Maven Project.本篇博客是JavaEE开发的开篇,也是基础.本篇博客的内容干货还是比较多的,而且比较实用,并且都是采用目前最新版本的工具 ...

  2. JavaEE开发之基于Eclipse的环境搭建以及Maven Web App的创建

    本篇博客就完整的来聊一下如何在Eclipse中创建的Maven Project.本篇博客是JavaEE开发的开篇,也是基础.本篇博客的内容干货还是比较多的,而且比较实用,并且都是采用目前最新版本的工具 ...

  3. eclipse创建maven web app

    1 这个功能是由eclipse的插件maven archetype plugin支持的 2 创建过程 File->New->Maven Project 选择archetype为maven- ...

  4. 【IDEA使用技巧】(5) —— IntelliJ IDEA集成Tomcat部署Maven Web项目

    1.IntelliJ IDEA集成Tomcat部署Maven Web项目 1.1.IDEA构建Maven Web项目 使用IDEA来创建一个简单的Hello World的Maven Web项目,并使用 ...

  5. 004.Create a web app with ASP.NET Core MVC using Visual Studio on Windows --【在 windows上用VS创建mvc web app】

    Create a web app with ASP.NET Core MVC using Visual Studio on Windows 在 windows上用VS创建mvc web app 201 ...

  6. Java create azure web app

    create a certificate <java-install-dir>/bin/ keytool -genkey -alias <keystore-id> -keyst ...

  7. Create an ASP.NET Core web app in Visual Studio Code

    https://www.microsoft.com/net/core#windowscmd https://download.microsoft.com/download/B/9/F/B9F1AF57 ...

  8. 亲手使用Sencha Touch + phonepag开发Web APP随笔 -- 第一个APP

    参考博文: [Phonegap+Sencha Touch] 移动开发1.准备工作 [Phonegap+Sencha Touch] 移动开发2.PhoneGap/Cordova初步使用   经过差不多1 ...

  9. Java Web学习系列——Maven Web项目中集成使用Spring、MyBatis实现对MySQL的数据访问

    本篇内容还是建立在上一篇Java Web学习系列——Maven Web项目中集成使用Spring基础之上,对之前的Maven Web项目进行升级改造,实现对MySQL的数据访问. 添加依赖Jar包 这 ...

随机推荐

  1. Delphi 绘图对象

    来自:http://blog.csdn.net/lailai186/article/details/8755430 ========================================== ...

  2. PHP下利用PHPMailer

    PHPMailer有什么优点? 可运行在任何平台之上 支持SMTP验证 发送邮时指定多个收件人,抄送地址,暗送地址和回复地址:注:添加抄送.暗送仅win平台下smtp方式支持 支持多种邮件编码包括:8 ...

  3. MySQL增删改数据

    1.增加数据 ,); /*插入所有字段.一定依次按顺序插入--字符串与日期需要加单引号,数字不需要,各个字段之间用逗号分隔*//*注意不能少或者多字段值*/ ,) /*按字段名插入数据,中间用逗号隔开 ...

  4. php极速后台开发框架LotusAdmin

    组件:基于thinkphp5.0.12+layui2.1版本 演示站点:https://www.lotusadmin.top/账号 : admin密码:123456 官方QQ交流群:606645328 ...

  5. scrapy 学习笔记2

    本章学习爬虫的 回调和跟踪链接 使用参数 回调和跟踪链接 上一篇的另一个爬虫,这次是为了抓取作者信息 # -*- coding: utf-8 -*- import scrapy class Myspi ...

  6. 【LOJ】#2014. 「SCOI2016」萌萌哒

    题解 这个题好妙啊 首先我们发现,如果我们可以暴力,就是把相同的元素拿并查集合起来,最后统计集合个数\(cnt\) 答案是\(9\*10^{cnt - 1}\) 然而我们做不到= = 我们可以用倍增的 ...

  7. 修改MySQL事件

    MySQL允许您更改现有事件的各种属性. 要更改现有事件,请使用ALTER EVENT语句,如下所示: ALTER EVENT event_name ON SCHEDULE schedule ON C ...

  8. Coding.net进阶,使用Git管理代码

    原文来自:http://conw.net/archives/18/ (我自己的博客,点击链接查看文章最新版本) Git是目前最流行的版本控制系统,这里以GitHub为例,介绍git的基本使用. Git ...

  9. CF986B Petr and Permutations [逆序对]

    题目传送门 Petr and Permutations 格式难调,题面就不放了. 分析: 胡乱分析+猜测SP性质一波.然后被学长告知:“1~n的排列交换次数与逆序对的奇偶性相同.”然后就愉快地A了. ...

  10. 洛谷——P1330 封锁阳光大学

    P1330 封锁阳光大学 题目描述 曹是一只爱刷街的老曹,暑假期间,他每天都欢快地在阳光大学的校园里刷街.河蟹看到欢快的曹,感到不爽.河蟹决定封锁阳光大学,不让曹刷街. 阳光大学的校园是一张由N个点构 ...