本文介绍了Maven中的代码生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从接口自动生成一些java类。我的第一个想法是编写代码生成器,并将其集成为maven插件。

I want to autogenerate some java classes from interfaces. My first thought was to write a code generator, and integrate it as a maven plugin.

我正在考虑创建一个带有codegen目标的maven插件,该插件在构建过程。

I was thinking of creating a maven plugin with a codegen goal that is called during the build process.

因此,如果我选择此路由,如何为插件提供要处理的接口?生成的文件应该放在哪里?

So if I choose this route, how do I provide the plugin with the interfaces to be processed? And where should the generated files go?

是否有任何现有的插件可以配置为生成默认的类实现?

Are there any existing plugins that can be configured to generate default class implementations?

推荐答案

来源应该进入{project.build.directory} / generated-sources / [plugin-id] /

Sources should go in {project.build.directory}/generated-sources/[plugin-id]/

大多数插件都通过pom中的插件配置部分进行配置。您也可以使用默认值,或者使用注释和类路径扫描。

Most plugins take configuration passed through the plugin configuration section in the pom. You can use default values as well, or an annotation and classpath scanning.

像生成代码,您可以查看。 使用Maven构建更好电子书还包含一个关于编写插件的相当全面的章节。

A plugin like the maven-jspc-plugin generates code, which you could take a look at. The "Better Builds With Maven" e-book also contains a reasonably comprehensive chapter on writing plugins.

这篇关于Maven中的代码生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 05:38