如何使用Maven War Plugin在战争之间重用战争资源 [英] Howto re-use War resources between Wars with Maven War Plugin

查看:104
本文介绍了如何使用Maven War Plugin在战争之间重用战争资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java EE环境下,我建立了一个包含几个JSP文件的网页. 可以说,其中包含的JSP之一是 header.jsp .可以非常类似于Stackoverflow使用的那种,显示有关用户,链接等的信息.此JSP链接到Java控制器以获取用户信息,并且是我的WAR文件(包括所有Web应用程序)的一部分.

Under a Java EE enviroment, I have a web page built including several JSP files. Lets say one of the included JSP is header.jsp. Can be very similar to the one used by Stackoverflow, showing info about the user, links etc. This JSP is linked to a java controller to fetch user info, and is part of my WAR file including all the web application.

我使用Eclipse进行开发,并使用Maven进行构建和打包.

To develop it I used Eclipse and to build and package it I use Maven.

现在,我需要构建一个新的webApplication(这样一场新的战争),并且我想重用该标头.

Now I need to build a new webApplication (so a new war) and I want to reuse the header.

我假装是:

  • 不重复代码
  • 两次战争都使用一种版本的标头代码

所以问题是:

有避免复制&的方法将两个文件(header.jsp和controller.java)从旧项目粘贴到新项目?

There is way to avoid copy & pasting both files (header.jsp & controller.java) from old project to the new one?

推荐答案

Maven WAR插件是为您处理WAR文件打包的插件,它提供了来解决此问题.您只需将项目的类型设置为"WAR",就已经在使用WAR插件; maven使用它作为如何构建项目的线索,包括将WAR插件用于软件包阶段绑定.

The Maven WAR plugin, which is the plugin that handles the packaging of a WAR file for you, provides the "Overlay" mechanism to solve exactly this issue. You are already using the WAR plugin simply by having your project be of type "WAR"; maven uses that as a clue as to how to build your project, including use of the WAR plugin for the package phase binding.

Overlay的工作方式是,您的WAR文件将另一个WAR项目声明为依赖项,就像您需要删除对所需jar文件的依赖项一样.当WAR插件的软件包mojo触发时,它将看到对另一个WAR的依赖关系,并结合两者来构建新的战争.请注意,如果两个WARS中都存在文件,则不会合并文件;否则,不会合并文件.一个简单地覆盖另一个.您可以配置插件以选择使用哪个插件.默认情况下,胜出的是当前项目的文件.另外请注意,如果您愿意,您可以不仅仅依靠一场战争.

The way the Overlay works is that your WAR file declares another WAR project as a dependency, just like you would delcare a dependency on a jar file you need. When the WAR plugin's package mojo fires, it will see this dependency on another WAR and build your new war as a combination of the two. Note, there is no merging of files if the file exists in both WARS; one simply overrides the other. You can configure the plugin to choose which one get's used; by default, it's the current project's file that wins. Also note, you can depend on more than just one war if you like.

这篇关于如何使用Maven War Plugin在战争之间重用战争资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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