基于 Maven 的代码生成器

发布于 2024-12-13 08:54:26 字数 967 浏览 0 评论 0原文

我需要在 Eclipse 项目中拥有一个 config.xml 文件,并使用该文件作为 Maven 目标的输入。该目标将使用 config.xml 在 generated/ 目录(也在我的项目中)下自动生成代码(XML 和 Java)。

因此:

MyProject/
    src/main/config
        config.xml
    src/main/java
        (All my Java source)
    (rest of my project)
    generated
        source/
            java/
            xml/

因此,Maven 目标将在任何与编译或构建相关的目标之前启动,并使用 config.xml 来填充generate/source/* 目录,因为我需要它们。这些来源随后可用于后续目标的处理。

这样的工具存在吗?我能找到的最接近的是XDoclet但我对此有两个担忧:

  1. 我不知道它有多灵活;即,我可以在多大程度上将我自己的配置“东西”放入 config.xml 中,给 XDoclet 一个 XSD 并让它去镇上;下面有更多内容
  2. 似乎找不到任何 Maven 目标/插件

至于第一个项目/问题,我的意思是这样的:理想情况下,我想将 任何 类型的 XML 放入其中config.xml。那么,这个理想的工具应该只需要该 XML 的 XSD,以及一些 XSLT(或类似的)来确定如何从配置文件中找到的 XML 自动生成代码。

我不确定 XDoclet 是否允许这种灵活性。

有什么想法或建议吗?那里一定有像这样的东西!提前致谢,

I have a need to have a config.xml file in my Eclipse project, and to use that file as the input to a Maven goal. That goal will use config.xml to auto-generate code (both XML and Java) under a generated/ directory (also in my project).

Thus:

MyProject/
    src/main/config
        config.xml
    src/main/java
        (All my Java source)
    (rest of my project)
    generated
        source/
            java/
            xml/

Thus the Maven goal would get kicked off prior to any compile- or build-related goals and would use config.xml to populate the generated/source/* directories as I need them. Those sources would then be available for subsequent goals to process.

Does such a tool exist? The closest I've been able to find is XDoclet but I have two concerns with it:

  1. I can't tell how flexible it is; i.e., to what degree I can put my own config "stuff" inside of config.xml, give XDoclet an XSD and let it go to town; more on this below
  2. Can't seem to find any Maven goals/plugins for it

As for the first item/issue, what I mean is this: ideally I'd like to put any kind of XML inside config.xml. So then, this ideal tool should only need an XSD for that XML, and some XSLT (or the likes) to determine how to autogenerate code from the XML found inside the config file.

I am not sure if XDoclet allows for such flexibility.

Any ideas or suggestions? There has to be something out there like this! Thanks in advance,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

海拔太高太耀眼 2024-12-20 08:54:26

XDoclet 非常灵活,但它的目的是处理 java 源并从中生成一些东西。如果您从一些 xml 开始,您最好的选择是 XSLT 转换 - xdoclet 不适合于此。

XDoclet is pretty flexible, but it purpose it to process java sources and generate something out of it. If you start with some xml, your best choice would be XSLT transformation - xdoclet ist not suitable for this.

玩物 2024-12-20 08:54:26

我使用 antrun 和与 Ant 配合使用的 xslt 任务来生成其他代码工件。然后使用 build-helper 插件将生成的文件夹添加到源文件夹列表中。这应该为您提供编写代码的最灵活的基础,并且也可以与 m2e 一起使用(尽管您需要自己运行 Maven 生成源,因为 antrun 不会自动运行,因为还没有连接器)。

I use antrun and the xslt task that works with Ant to generate other code artifacts. Then use build-helper plugin to add the generated folders to the source folder list. This should provide you with the most flexible base of writing the code and will also work with m2e (though you need to run the maven generate-sources yourself as antrun won't run automatically as there is no connector for it yet).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文