Java预处理阶段 [英] Java preprocess phase

查看:61
本文介绍了Java预处理阶段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个 Java 应用程序,它需要存储在许多枚举类型中的大量静态数据.由于我想要一种用户友好的方式来使用例如 xml 或 json 文件来自定义此数据,但我不允许直接使用枚举来执行此操作,因此我正在寻找一种优雅地执行此操作的方法.

I'm writing a Java application that needs a lot of static data that is stored in many enum types. Since I would like an user-friendly way to customize this data using for example xml or json files but I'm not allowed to do it directly with enums I was looking for a way to elegantly do it.

也许一个好的解决方案是有一个单独的 java 程序来读取 xml 文件并生成 java 源,然后与源的其余部分一起编译.我的疑虑是如何以独立的方式(例如 ant?)自动化这个过程,以及如何将它与 eclipse 无缝集成,以便在我处理项目时自动完成.寻找已经存在?有什么建议可以解决我的问题?

Maybe a good solution would be to have a separate java program that reads the xml files and produces the java sources that are then compiled with the remaining part of the sources. My doubs is how to automatize this process in a stand alone way (eg ant?) and how to integrate it seamlessly with eclipse so that it is autOmatically done when I'm working with the project.. Does anything similar to what I'm looking already exists? Any suggestion to solve my problem?

谢谢!

推荐答案

创建一个项目,其唯一工作是从您的源代码生成 Java.确保生成阶段由 Ant 完成.

Create a project whose sole job is to generate java from your sources. Make sure that the generation phase is done by Ant.

现在,将此项目包装到 eclipse 中并使用自定义 ant 构建器,该构建器调用现有 build.xml 中的目标.

Now, wrap this project into eclipse and use a custom ant builder, that calls the target in your already existing build.xml.

这是我们开发基础设施的标准部分,所以这绝对有效.

This is a standard part of our dev infrastructure, so this definitely works.

这篇关于Java预处理阶段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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