从pom.xml为现有Maven项目创建WAR文件 [英] Create WAR file from pom.xml for an existing Maven project
问题描述
我正在创建一个Web项目,我被告知它必须驻留在现有maven项目的资源目录中
I am creating a web project and I was told that it has to reside inside the resources directory of an existing maven project
这是项目的结构
MavenProject
|-- src
| |-- main
| `-- resources
| `-- My-Web-Project
| |-- META-INF
| | `-- MANIFEST.MF
| |-- src
| | |-- classes
| | | |-- com
| | | | `-- example
| | | | `-- projects
| | | | `-- SampleAction.class
| `-- web
| |-- css
| |-- css
| |-- img
| |-- js
| |-- WEB-INF
| | `-- web.xml
| |-- index.jsp
| `-- secondary.jsp
|-- test
`-- pom.xml
正如您所看到的,MavenProject已经有一个pom.xml文件。我希望能够使用当前的pom.xml部署我的Web项目WAR。
As you can see there is already a pom.xml file for the MavenProject. I want to be able to deploy my web project WAR using the current pom.xml.
我想知道是否可以这样做以及如何继续创建Maven插件。
I want to know if it's possible to do this and how would I proceed to create the Maven Plugin.
我读过这篇文章,但我不知道它是否适用于我的情况
http://maven.apache.org/plugins/maven-war-plugin/usage.html
I read this article but I don't know if it apply to my situation http://maven.apache.org/plugins/maven-war-plugin/usage.html
编辑:
我正在使用tomcat应用服务器。
I am using tomcat app server.
如前所述,我的项目My-Web-Project应位于资源下
As Mentioned before, My project "My-Web-Project" should be under "resources"
推荐答案
阅读本文档,不完整,但它是好的首发。
Read this document, incomplete, but it is good starter.
- Using maven using non standard directory layout
示例配置(不推荐)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<webResources>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>src/main/resources/My-Web-Project/web</directory>
</resource>
</webResources>
</configuration>
</plugin>
这不完整,目标
和班级不应位于源目录内。
This is not complete, target
and classes shouldn't be located inside source directory.
我被告知它(web项目)必须驻留在现有maven项目的资源目录中
I was told that it (web project) has to reside inside the resources directory of an existing maven project
这是错误的,不应在资源内部创建Web项目!
了解 Maven Convention over Configuration 。
约定优于配置是一个简单的概念。系统,库和框架应该采用合理的默认值。不需要不必要的配置,系统应该正常工作。
Convention over configuration is a simple concept. Systems, libraries, and frameworks should assume reasonable defaults. Without requiring unnecessary configuration, systems should "just work".
使用约定代替配置。
正确的目录结构应如下所示这个:
Use convention instead of configuration.
Proper directory structure should looks like this:
MavenProject
|-- src
| |-- main
| | `-- java
| | `-- com
| | `-- example
| | `-- projects
| | `-- SampleAction.java
| `-- resources
| | `-- META-INF
| | `-- MANIFEST.MF
| `-- webapp
| |-- css
| |-- img
| |-- js
| |-- WEB-INF
| | `-- web.xml
| |-- index.jsp
| `-- secondary.jsp
|-- test
|-- target // this is generated by maven!
| |-- classes
| | `-- com
| | `-- example
| | `-- projects
| | `-- SampleAction.class
`-- pom.xml
来源:标准目录布局简介
这篇关于从pom.xml为现有Maven项目创建WAR文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!