A Java project's conventions can be built into the source files the IDE generates. In Eclipse on the Linux desktop, you can configure Java code templates to set the boilerplate for new files, such as a standard header comment.

The Files comment template supplies the header text when comment generation is enabled and Use markdown comments where available is clear. Eclipse inserts the header at ${filecomment} in the New Java files code template.

Workspace templates apply to projects that inherit the workspace settings. Eclipse uses the saved pattern the next time it generates matching source.

Steps to configure code templates in Eclipse:

Start in the Java perspective with the source folder of a fresh Java project visible in Package Explorer. The project inherits the workspace code templates, and New Java files is set to Eclipse's default template, which puts ${filecomment} on the first line. On the Code Templates page, Use markdown comments where available must be clear. When it is checked, projects set to Java 23 or later use Markdown Comments > Files instead. Use a project name that is valid as a Java package name so Eclipse can fill in Package in the class wizard. The example uses demo/src in ~/eclipse-workspace.

If Eclipse shows the Install Java 27 Support notice, the choice is yours. Remind Me Later dismisses it so you can start at step 1.

  1. Open the Window menu.
  2. Click Preferences….
  3. Type Code Templates in the Preferences filter.
  4. Select Code Templates under Java > Code Style.
  5. Expand Comments in the template tree.
  6. Select Files under Comments.
  7. Click Edit… to open the selected template.
  8. Select the existing text in Pattern with Ctrl+A.
  9. Type your file header as a Java comment in Pattern, using /* Demo application source. */ as an example.
  10. Click OK to accept the edited template.
  11. Click Apply and Close to save the workspace template.
  12. Right-click your project's Java source folder (src in the example) in Package Explorer.
  13. Point to New in the source folder's context menu.
  14. Choose Class from the New submenu.
  15. Enter an unused class name such as Greeter in Name.
  16. Scroll down inside the New Java Class wizard until Generate comments is visible.
  17. Set Generate comments to checked.
  18. Click Finish to generate the class.
  19. Confirm that your file header appears on the first line of the new class file in the editor.

    The first line of Greeter.java reads /* Demo application source. */ above the package demo; declaration.

Share this guide