在 Java 构建过程中更改常量的最佳方法 [英] Best way to alter constants in Java build process

查看:40
本文介绍了在 Java 构建过程中更改常量的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承了一个在 Tomcat 下运行的 Java 应用程序 (servlet).由于历史原因,代码具有不同的外观和感觉"选项,具体取决于应用的部署位置(本质上是品牌问题).

I have inherited a Java application (servlets) that runs under Tomcat. For historical reasons, the code has different "look and feel" options based on where the application will be deployed (essentially a matter of branding).

有几个常量控制着这个品牌化过程,它们有不同的功能,不应该被压缩成一个常量(即品牌、多语言、加上图标和css样式表的位置等).

There are several constants that control this branding process, which have different functions and should not be compacted into a single constant (i.e. BRAND, MULTI-LANGUAGE, plus the locations of icons and css style sheets, etc.).

目前,开发团队必须手动更改常量(它们至少在一个数据类中本地化并有详细记录),然后使用 ANT 重新编译应用程序.

Currently the development team must manually change the constants (they are at least localized in one data class and well documented), then recompile the application using ANT.

假设至少使用 Ant 1.8 和 Java 6.x,自动化此过程的最佳方法是什么?

What is the best way to automate this process assuming at least Ant 1.8 and Java 6.x?

我知道使用编译器参数没有任何好的解决方案(就像在 C 或 C++ 中可以做的那样),并且我倾向于某种最佳方法"来编辑包含常量的源文件,或将它们放入另一个文件并使用 ant 构建过程将它们换出.我想要一个结果,它可以使用ant build brand-x"之类的东西,其中更改品牌会改变生成的构建.

I know that there have not been any good solutions using compiler arguments (like one could do in C or C++), and am leaning to some "best way" to edit either the source file containing the constants, or putting them into another file and swapping them out using the ant build process. I'd like to have a result that would work using something like "ant build brand-x" where changing the brand would change the resulting build.

谢谢,

-理查德

推荐答案

使用 Ant 中的替换任务来更改值.

Use the replace task in Ant to change the values.

这篇关于在 Java 构建过程中更改常量的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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