Question

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

I chose the Apache-2.0 License. You will obviously need to make adjustments for your choice of license.

Add to your pom file:

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

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:

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

Was it helpful?

Solution

User Property

  1. Select Tools ---> Templates, and click Settings button.

  2. Edit the User.properties file to establish the user property: e.g., user=your full name <your email/contact info>

By default the user property in the User.properties file is commented out. 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.

OTHER TIPS

If you want a PROJECT specific way (User.properties is global), you will have to change the license header template. 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. See this netbeans.org issue

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top