Java 简单 Servlet 应用程序的 Maven 原型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2782066/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maven archetype for simple Servlet application
提问by deamon
Is there a Maven 2 archetype for a simple Servlet (2.5) web application?
是否有用于简单 Servlet (2.5) Web 应用程序的 Maven 2 原型?
采纳答案by Pascal Thivent
There isan archetype for webapp:
这里是一个原型Web应用程序:
mvn archetype:generate -DgroupId=com.acme \
-DartifactId=my-webapp \
-Dversion=1.0-SNAPSHOT \
-DarchetypeArtifactId=maven-archetype-webapp \
-DinteractiveMode=false
This will generate the following structure:
这将生成以下结构:
$ tree my-webapp/ my-webapp/ ├── pom.xml └── src └── main ├── resources └── webapp ├── index.jsp └── WEB-INF └── web.xml
Where the web.xml is a Servlet 2.3 web.xml:
其中 web.xml 是 Servlet 2.3 web.xml:
$ cat my-webapp/src/main/webapp/WEB-INF/web.xml
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
</web-app>
For a Servlet 2.5 web application, replace it with something like this:
对于 Servlet 2.5 Web 应用程序,将其替换为以下内容:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>Archetype Created Web Application</display-name>
</web-app>
I don't know for NetBeans but Eclipse (more precisely M2Eclipse) relies on the web.xml
to set the project facets (so you need to change the web.xml
before the import, Eclipse won't update the web facet if you change the web.xml
after the facts).
我不知道 NetBeans,但 Eclipse(更准确地说是 M2Eclipse)依赖于web.xml
设置项目方面(因此您需要web.xml
在导入之前更改,如果您在web.xml
事后更改,Eclipse 将不会更新 Web 方面)。
回答by diy
you can start with
你可以从
mvn archetype:create -DgroupId=com.mycompany.app -DartifactId=my-webapp -DarchetypeArtifactId=maven-archetype-webapp
For a list of other archetypes,please refere to archetypes list
有关其他原型的列表,请参阅 原型列表
回答by jeevatkm
Updated archetype number.
更新原型编号。
Note: By default archetype 'maven-archetype-webapp' generates Servlet 2.3 application. For upgrading to Servlet 2.5 kindly follow post #1343356from Pascal Thivent
注意:默认情况下,原型 'maven-archetype-webapp' 生成 Servlet 2.3 应用程序。要升级到 Servlet 2.5,请关注Pascal Thivent 的帖子 #1343356
Refer this link Exclusive Maven Archetype Listand follow this link for How to use that archetype.
请参阅此链接Exclusive Maven Archetype List并点击此链接了解如何使用该原型。
Frequently used archetype numbers are:
经常使用的原型数字是:
- 610 -> org.apache.maven.archetypes:maven-archetype-webapp (An archetype which contains a sample Maven Webapp project)
- 600 -> org.apache.maven.archetypes:maven-archetype-j2ee-simple (An archetype which contains a simplifed sample J2EE application.)
- 610 -> org.apache.maven.archetypes:maven-archetype-webapp(包含示例 Maven Webapp 项目的原型)
- 600 -> org.apache.maven.archetypes:maven-archetype-j2ee-simple(包含简化的示例 J2EE 应用程序的原型。)
OR just use below handy maven command-
或者只需使用以下方便的 maven 命令-
$ mvn archetype:generate -DgroupId=com.sample -DartifactId=servlet-app -Dversion=0.1-SNAPSHOT -DarchetypeArtifactId=maven-archetype-webapp
回答by Maciej Walkowiak
I have created simple archetype for creating Servlet 3 based webapps: http://maciejwalkowiak.github.io/servlet3-maven-archetype/
我为创建基于 Servlet 3 的 webapps 创建了简单的原型:http: //maciejwalkowiak.github.io/servlet3-maven-archetype/
Just clone it, install and generate project that uses Servlet 3, no XML, Tomcat7 ready (plugin included)
只需克隆它,安装并生成使用 Servlet 3 的项目,无需 XML,已准备好 Tomcat7(包括插件)
回答by Bimales Mandal
- Create maven project using maven-archetype-webapp archetype
- 使用 maven-archetype-webapp 原型创建 maven 项目
command: mvn archetype:create -DgroupId=com.lei.webapp.quickstart -DartifactId=webapp-quick-start -DarchetypeArtifactId=maven-archetype-webapp
命令: mvn archetype:create -DgroupId=com.lei.webapp.quickstart -DartifactId=webapp-quick-start -DarchetypeArtifactId=maven-archetype-webapp
Add following dependency in pom.xml :
javax.servlet servlet-api 2.5
在 pom.xml 中添加以下依赖项:
javax.servlet servlet-api 2.5
回答by cmb28
I let the IDE (mine is Intellij IDEA) create the basic webapp structure for me.
我让 IDE(我的是 Intellij IDEA)为我创建了基本的 webapp 结构。
Go to:
去:
File → New Project → create from archetype → ...archetype-webapp
文件 → 新建项目 → 从原型创建 → ...archetype-webapp
This will give the basic webapp structure.
这将给出基本的 webapp 结构。