How to create a Maven web app and deploy to Tomcat - fast
原文地址: 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 |
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
- WEB-INF
- main
- pom.xml
- src
- .project
- webapp
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.)
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> |
... |
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
.
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的更多相关文章
- JavaEE开发基于Eclipse的环境搭建以及Maven Web App的创建
本篇博客就完整的来聊一下如何在Eclipse中创建的Maven Project.本篇博客是JavaEE开发的开篇,也是基础.本篇博客的内容干货还是比较多的,而且比较实用,并且都是采用目前最新版本的工具 ...
- JavaEE开发之基于Eclipse的环境搭建以及Maven Web App的创建
本篇博客就完整的来聊一下如何在Eclipse中创建的Maven Project.本篇博客是JavaEE开发的开篇,也是基础.本篇博客的内容干货还是比较多的,而且比较实用,并且都是采用目前最新版本的工具 ...
- eclipse创建maven web app
1 这个功能是由eclipse的插件maven archetype plugin支持的 2 创建过程 File->New->Maven Project 选择archetype为maven- ...
- 【IDEA使用技巧】(5) —— IntelliJ IDEA集成Tomcat部署Maven Web项目
1.IntelliJ IDEA集成Tomcat部署Maven Web项目 1.1.IDEA构建Maven Web项目 使用IDEA来创建一个简单的Hello World的Maven Web项目,并使用 ...
- 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 ...
- Java create azure web app
create a certificate <java-install-dir>/bin/ keytool -genkey -alias <keystore-id> -keyst ...
- 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 ...
- 亲手使用Sencha Touch + phonepag开发Web APP随笔 -- 第一个APP
参考博文: [Phonegap+Sencha Touch] 移动开发1.准备工作 [Phonegap+Sencha Touch] 移动开发2.PhoneGap/Cordova初步使用 经过差不多1 ...
- Java Web学习系列——Maven Web项目中集成使用Spring、MyBatis实现对MySQL的数据访问
本篇内容还是建立在上一篇Java Web学习系列——Maven Web项目中集成使用Spring基础之上,对之前的Maven Web项目进行升级改造,实现对MySQL的数据访问. 添加依赖Jar包 这 ...
随机推荐
- GPS位置模拟-安卓
测试定位功能时都需要位置模拟,一般有如下3种方式: a)手机上安装第三方模拟软件:需要Root: b)PC模拟其中运行app并模拟位置:不能在真机上运行,手机兼容性不能测试到: b)在app中让开发增 ...
- Java容器概述
如果一个程序只包含固定数量的且其生命期都是己知的对象. 那么这是一个非常简单的程序. 通常,程序总是根据运行时才知道的某些条件去创建新对象.在此之前,不会知道所需对象的数量,甚至不知道确切的类型.为解 ...
- 获取ios设备系统信息的方法 之 [UIDevice currentDevice]
获取iphone的系统信息使用[UIDevice currentDevice],信息如下: [[UIDevice currentDevice] systemName]:系统名称,如iPhone OS ...
- 元组tuple常用方法
元组tuple的功能类似与列表,元组有的功能,列表都有,列表有的,元组不一定有,下面来看看元组具有的功能: 1.count(self,value) count(self,value)统计元组中 ...
- python collections模块详解
参考老顽童博客,他写的很详细,例子也很容易操作和理解. 1.模块简介 collections包含了一些特殊的容器,针对Python内置的容器,例如list.dict.set和tuple,提供了另一种选 ...
- python lxml教程
目前有很多xml,html文档的parser,如标准库的xml.etree , beautifulsoup , 还有lxml. 都用下来感觉lxml不错,速度也还行,就他了. 围绕三个问题: 问题 ...
- 【C#日期系列(三)】--C#获取某个月的第一个星期几的年月日
需要获取某个月的第一个星期几的年月日 简单写了一个算法 #region 计算每月第一个星期1-7是各是几号 /// <summary> /// 计算每月第一个星期1-7是各是几号 /// ...
- Knockout介绍
Knockout.js是什么? Knockout是一款很优秀的JavaScript库,它可以帮助你仅使用一个清晰整洁的底层数据模型(data model)即可创建一个富文本且具有良好的显示和编辑功能的 ...
- Python - 软件设计规范
为什么要设计好目录结构? "设计项目目录结构",就和"代码编码风格"一样,属于个人风格问题.对于这种风格上的规范,一直都存在两种态度: 一类同学认为,这种个人风 ...
- Building Robust and Flexible Event System in Unity3D
Building Robust and Flexible Event System in Unity3D 1. Prerequisites 1.1 Observer Pattern According ...