为单个Maven项目创建两个工件(战争) [英] Create two artifacts (war) for a single maven project

查看:68
本文介绍了为单个Maven项目创建两个工件(战争)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java Web项目,我们将其部署在两个不同客户的服务器上,其中99%的代码是相同的,现在我有两个ApplicationBuilder,该类包含为每个客户定制的类.

I have a Java web project that we deploy on the server of two different customers, 99% of the code is the same, right now I have two ApplicationBuilders, which is the class that contains the customization for each customer.

每次我要部署新版本时,我都必须手动注释一行,使用maven进行构建,取消注释该行,注释另一行,然后再次构建.

Anytime I want to deploy the new version I have to manually comment a line, build (with maven), uncomment that line, comment the other one and build again.

public class ApplicationBuilderFactory {
    private static final IApplicationBuilder app;

    static {
//            app = new Customer1ApplicationBuilder()
            app = new Customer2ApplicationBuilder();
        }
    }

    public static IApplicationBuilder get() { return app; }
}

我想避免所有这些,最好的事情可能只是造成两次不同的战争.

I want to avoid all this and the best thing would probably just create two different wars.

执行此操作的好方法是什么?我不使用(也不喜欢)依赖项注入框架,仅为单个类添加一个框架似乎过头了,但我可能会考虑.

What's a good way to do this? I don't use (nor like) dependency injection frameworks and it seems overkill to add one just for a single class, but I may consider it.

推荐答案

一种解决方法是使用您可以创建一个基本的WAR项目,然后为每个仅包含需要不同组件的客户创建一个单独的WAR项目,而不是尝试从一个项目构建多个工件(一段时间后可能变得笨拙).

Instead of trying to build multiple artifacts from one project (which can become unwieldy after a while), you create one base WAR project, and then a separate WAR project for each customer that only contains the components that need to be different.

每个特定于客户的WAR将与基本WAR重叠.这样不仅可以轻松自定义ApplicationBuilderFactory,还可以自定义特定的Web内容和资产.

Each customer specific WAR will be overlaid with the base WAR. This will make it easier to customise not only the ApplicationBuilderFactory but also specific web content and assets.

这还具有以下好处

  • 特定于客户的功能必须保证彼此隔离;

  • customer specific features are guaranteed to be isolated from each other;

不同的客户可以拥有自己的发布周期和源代码控制库

different customers can have their own release cycle and source control repository

添加后续客户很容易

这篇关于为单个Maven项目创建两个工件(战争)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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