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包 这 ...
随机推荐
- SuSE Linux Supervisor的安装与使用案例
建议使用 root 管理员账户操作 1.安装工具 1.apache 2..Net Core(dotnet-sdk-2.0) 3.Supervisor(进程管理工具,目的是服务器一开机就启动服务器 ...
- 洛谷 P1568赛跑 题解
题目传送门 这道题非常的水,只要你能搞清楚题意,将SH.KC不要混起来即可(所以我使用了结构体) #include<bits/stdc++.h> using namespace std; ...
- gcc编译器参数
[gcc编译步骤] 1.预处理,生成.i的文件[预处理器cpp] 2.将预处理后的文件转换成汇编语言,生成文件.s[编译器egcs] 3.由汇编变为目标代码(机器代码)生成.o的文件[汇编器as] 4 ...
- ubuntu 系统提示升级失败,boot空间不足
系统提示升级失败,boot空间不足,解决方法: linux 随着系统的升级,会自动攒下好几个内核 执行 uname -a 看下自己当前启动的是哪个内核 dpkg --get-selections |g ...
- java总结(一)(变量类型)
java代码运行原理 需要注意 公共类类名必须和文件名相同 一个文件可以有好几个类,编译生成n个类文件名 chcp 65001----utf8 936----GBK 437----美国英语 文档注释必 ...
- LongAdder & AtomicInteger
JDK8 推荐 LongAdder替代 AtomicInteger, AtomicInteger内部是实现使用 (网友使用jad反编译源码 参考 http://ifeve.com/enhanced- ...
- HDU 6071 Lazy Running (同余最短路 dij)
Lazy Running Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)To ...
- Scrapy基础------css选择器基础
基本语法: * 选择所有节点 #container 选择id为container的节点 .container 选择所有class包含container的节点 li a 选取所有li 下所有a节点 ul ...
- [BZOJ 2821] 作诗
Link: BZOJ 2821 传送门 Solution: 一道类似区间众数的经典分块 由于个数为偶数这样的条件不能支持快速合并 因此要先$O(n*sqrt(n))$预处理出$pre[i][j]$表示 ...
- CodeForces - 1016C Vasya And The Mushrooms
题面在这里! 好久没有体会这种A题的快感了23333 一开始看错了,以为权值是从1开始的,不过这样不要紧,最后把算的答案减去两行数的和就是正确的答案了. 然后发现位于一个角上的时候,我们其实只有两种选 ...