2

我已经添加了:

<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 版本中,这将不是必需的。

4

2 回答 2

3

用户属性

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

  2. 编辑User.properties file以建立user property:例如,user=your full name <your email/contact info>

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

我希望这可能会有所帮助。

于 2013-04-04T02:15:22.653 回答
1

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

于 2013-04-04T18:53:12.637 回答