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

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

问题描述

我已经继承了一个在Tomcat下运行的Java应用程序(servlet)。由于历史原因,代码根据应用程序部署的位置(基本上是品牌问题)有不同的外观和感觉选项。



有几个常量控制这个品牌化过程,它们具有不同的功能,并且不应被压缩成单个常量(即BRAND,MULTI-LANGUAGE,加上图标和CSS样式表等的位置)。



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





我知道使用编译器参数没有任何好的解决方案就像一个可以在C或C ++中做的),并且倾向于一些最好的方式来编辑包含常量的源文件,或将它们放入另一个文件,并使用ant构建过程交换出来。我想要一个结果,使用像ant build brand-x这样的工具,改变品牌会改变生成的结构。



谢谢, p>

-Richard

解决方案

使用Ant中的replace任务来更改值




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

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

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.

What is the best way to automate this process assuming at least Ant 1.8 and Java 6.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.

Thanks,

-Richard

解决方案

Use the replace task in Ant to change the values.

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

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