用于简单 Servlet 应用程序的 Maven 原型 [英] Maven archetype for simple Servlet application

查看:24
本文介绍了用于简单 Servlet 应用程序的 Maven 原型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有用于简单 Servlet (2.5) Web 应用程序的 Maven 2 原型?

解决方案

webapp的原型:

mvn archetype:generate -DgroupId=com.acme -DartifactId=my-webapp -Dversion=1.0-快照-DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

这将生成以下结构:

<前>$ tree my-webapp/我的网络应用程序/├── pom.xml└── src└── 主要├──资源└── 网页应用├── index.jsp└── 网络信息└── web.xml

其中 web.xml 是 Servlet 2.3 web.xml:

$ cat my-webapp/src/main/webapp/WEB-INF/web.xml<!DOCTYPE 网络应用程序公共-//Sun Microsystems, Inc.//DTD Web 应用程序 2.3//EN"http://java.sun.com/dtd/web-app_2_3.dtd"><网络应用程序><display-name>原型创建的 Web 应用程序</display-name></web-app>

对于 Servlet 2.5 Web 应用程序,将其替换为如下内容:

<display-name>原型创建的 Web 应用程序</display-name></web-app>

我不知道 NetBeans,但 Eclipse(更准确地说是 M2Eclipse)依赖于 web.xml 来设置项目方面(因此您需要更改 web.xmlcode> 在导入之前,如果您在事实之后更改 web.xml,Eclipse 将不会更新 web facet).

Is there a Maven 2 archetype for a simple Servlet (2.5) web application?

解决方案

There is an archetype for webapp:

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:

$ 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:

<?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).

这篇关于用于简单 Servlet 应用程序的 Maven 原型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆