【问题标题】:Change the {user} for a Maven project更改 Maven 项目的 {user}
【发布时间】:2013-03-25 21:47:24
【问题描述】:

我已添加:

<licenses>
  <license>
    <name>The Apache Software License, Version 2.0</name>
    <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
    <distribution>repo</distribution>
    <comments>A business-friendly OSS license</comments>
  </license>
</licenses>

到我的 pom 文件中,Apache 许可证整齐地出现在我创建的每个新源文件中。但是,许可文本显示为:

/*
 * Copyright 2013 MyUserName.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
   ...
 */

我希望它是

/*
 * Copyright 2013 OldCurmudgeon <--- Note the new name.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
   ...
 */

这个字段看起来像是来自{user} 属性,或者模板所暗示的。有什么方法可以根据每个项目进行更改吗?


答案在对以下提供的选项进行了一些试验后。

我对 pom 文件更改的看法是正确的。

我选择了 Apache-2.0 许可证。您显然需要针对您选择的许可证进行调整。

添加到您的 pom 文件中:

<licenses>
  <license>
    <name>The Apache Software License, Version 2.0</name>
    <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
    <distribution>repo</distribution>
    <comments>A business-friendly OSS license</comments>
  </license>
</licenses>

更改 Java 模板(工具/模板/Java/Java 类(以及您希望的任何其他)/在编辑器中打开(按钮))

变化:

 ...
 * @author ${user}
 ...

 ...
 * @author ${project.property.user}
 ...

然后更改许可证文件(工具/模板/许可证/您选择的许可证/在编辑器中打开(按钮))

...
${licensePrefix}Copyright ${date?date?string("yyyy")} ${project.organization!user}.
...

...
${licensePrefix}Copyright ${date?date?string("yyyy")} ${project.property.user}.
...

然后添加到你的 pom 文件中:

<properties>
  <!-- For the License -->
  <user>OldCurmudgeon</user>
</properties>

你就完成了。可惜我不得不更改许可证文件。也许在以后的 NetBeans 版本中,这将不是必需的。

【问题讨论】:

    标签: maven licensing netbeans-7.3


    【解决方案1】:

    用户属性

    1. 选择工具--->模板,然后点击设置按钮。

    2. 编辑User.properties file 以建立user property:例如user=your full name &lt;your email/contact info&gt;

    默认情况下,User.properties file 中的user property被注释掉。取消注释并编辑此行以向模板处理器提供一个漂亮的字符串。请注意向此文件添加其他属性然后在自定义模板中使用它们的可能性。

    我希望这会有所帮助。

    【讨论】:

    • 谢谢 - 我可以补充一下 Settings 实际上是一个按钮。
    • 请随意编辑。这将有助于我们保持质量和改进。
    【解决方案2】:

    如果您想要一个 PROJECT 特定的方式(User.properties 是全局的),您将不得不更改许可标头模板。将值从 ${user} 更改为 ${project.property.user},然后在每个项目 pom.xml 文件中的 project/properties pom 元素中声明一个“用户”属性。看到这个netbeans.org issue

    【讨论】:

      猜你喜欢
      • 2012-01-12
      • 1970-01-01
      • 2019-01-08
      • 2011-01-05
      • 2013-12-15
      • 2021-10-28
      • 1970-01-01
      • 2011-05-21
      • 1970-01-01
      相关资源
      最近更新 更多