简体   繁体   English

更改Maven项目的{user}

[英]Change the {user} for a Maven project

I have added: 我已经添加了:

<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>

to my pom file and the Apache license neatly appears in each new source file I create. 到我的pom文件中,并且Apache许可证整齐地出现在我创建的每个新源文件中。 However, the license text appears as: 但是,许可证文本显示为:

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

I want it to be 我希望它成为

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

this field looks like it comes from a {user} property, or so the template suggests. 此字段看起来像是来自{user}属性,因此模板建议使用。 Is there any way I can change that on a per-project basis? 有什么方法可以针对每个项目进行更改吗?


The answer after some experimenting with the offered options below. 经过尝试以下提供的选项后的答案

I was right about the pom file change. 我对pom文件更改是正确的。

I chose the Apache-2.0 License. 我选择了Apache-2.0许可证。 You will obviously need to make adjustments for your choice of license. 显然,您将需要对许可证的选择进行调整。

Add to your pom file: 添加到您的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>

Change the Java templates (Tools/Templates/Java/Java Class(and any others as you wish)/Open In Editor(button)) : 更改Java模板(工具/模板/ Java / Java类(以及您需要的任何其他类)/在编辑器中打开(按钮))

Change: 更改:

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

to

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

Then change the license file (Tools/Templates/Licences/The license you chose/Open In Editor(button)) : 然后更改许可证文件(工具/模板/许可证/您选择的许可证/在编辑器中打开(按钮))

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

to

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

Then add to your pom file: 然后添加到您的pom文件中:

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

And you're done. 这样就完成了。 Shame I had to change the license file. 可惜我不得不更改许可证文件。 Perhaps in a later release of NetBeans this won't be necessary. 也许在以后的NetBeans版本中,这不是必需的。

User Property 用户属性

  1. Select Tools ---> Templates, and click Settings button. 选择工具--->模板,然后单击设置按钮。

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

By default the user property in the User.properties file is commented out . 默认情况下, User.properties fileuser property 被注释掉 Uncomment and edit this line to provide a pretty string to the template processor. 取消注释并编辑此行以为模板处理器提供漂亮的字符串。 Note the possibility of adding other properties to this file and then using them in customized templates. 请注意,可以向该文件添加其他属性,然后在自定义模板中使用它们。

I hope this may help. 希望对您有所帮助。

If you want a PROJECT specific way (User.properties is global), you will have to change the license header template. 如果要使用特定于PROJECT的方式(User.properties为全局),则必须更改许可证标头模板。 Change the value from ${user} to ${project.property.user} and then in each of your project pom.xml files declare a "user" property within the project/properties pom element. 将值从$ {user}更改为$ {project.property.user},然后在每个项目的pom.xml文件中,在project / properties pom元素中声明一个“ user”属性。 See this netbeans.org issue 看到这个netbeans.org问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM