java - 使用自定义 Maven 原型(prototype)编辑源文件

标签 java maven-2 maven-archetype

我创建了一个客户 Maven 原型(prototype),并使用一些自定义的 requiredProperties 对其进行了设置:

<requiredProperties>
    <requiredProperty key="classPrefix" />
</requiredProperties>

我可以使用该属性来命名文件,如下所示:

__classPrefix__Config.java

我的问题是我可以在文件内使用该属性吗?我尝试了以下两种变体,但都不起作用:

public class ${classPrefix}Config
public class __classPrefix__Config

最佳答案

是的,你可以。 这是 _classPrefix_Config.java 的工作示例。

#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package};

/**
 * this is the prefixed class
 */
public class ${classPrefix}Config{ }

请确保您已在 archetype-metadata.xml 中启用过滤,如下所示:

<fileSet filtered="true">

(我正在开发 Maven 3)

关于java - 使用自定义 Maven 原型(prototype)编辑源文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3085893/

相关文章:

java - 如何才能拥有一组总值(value)最大的 JSpinner 对象?

eclipse - 将公共(public)配置添加到 m2eclipse 时出现问题

java - 使用 maven 使用 log4j 构建项目

java - 在已创建的 Java 项目中生成模板

java - 如何使用java代码与系统命令行交互

java - Android:使用 Stripe API 创建新的客户记录

java - 自定义 maven 插件 : install and execute the plugin in one build

java - Maven - 在 Quickstart Archetype 中更改 jUnit 版本

java - Spring MVC : Bad request (parameter missing) on file upload even when required parameters are present

java - maven安装的问题