如何添加包级别注释或编辑package-info.java?

时间:2022-10-30 14:40:12

I'm trying to add package level annotations but I don't have a clue on how to do it. Examples are appreciated.

我正在尝试添加包级别注释,但我不知道如何做到这一点。赞赏的例子。

4 个解决方案

#1


26  

Summary from the article here

这篇文章摘要

In package-info.java:

@PackageLevelAnnotation
package blammy; // package with a package level annotation.


import blammy.annotation.PackageLevelAnnotation;

In PackageLevelAnnotation.java

package blammy.annotation;

@Retention(RetentionPolicy.CLASS)
@Target(ElementType.PACKAGE)
public @interface PackageLevelAnnotation
{
  // stuff as required.
}

Edit: more package level info. Here is a link to the package chapter in the Java Language Spec: packages

编辑:更多包级别信息。以下是Java语言规范包中的包章节的链接

#2


38  

In eclipse

Since package-info.java isn't a valid identifier for a class it cannot be created as a class in Eclipse.

由于package-info.java不是类的有效标识符,因此无法在Eclipse中将其创建为类。

I found that when you create a new package there is a check box to check if you want a package-info.java.

我发现当你创建一个新包时,有一个复选框来检查你是否想要一个package-info.java。

To create a package-info.java file in an existing package:

要在现有包中创建package-info.java文件:

  1. Right-click on the package where you want a package-info.java.
  2. 右键单击要包含package-info.java的包。

  3. Select New->Package.
  4. Check the Create package-info.java check box.
  5. 选中Create package-info.java复选框。

  6. Click on Finish.
  7. 单击Finish。

#3


3  

Open explorer, go to src/your package folder.
right click -> Create new textfile: name it package-info.java.

打开资源管理器,转到src /你的包文件夹。右键单击 - >创建新的文本文件:将其命名为package-info.java。

Go back to eclipse and edit and add the desired content.

返回eclipse并编辑并添加所需内容。

#4


2  

The package-info.java is a Java file that can be added to any Java source package. Its purpose is to provide a home for package level documentation and package level annotations. Simply create the package-info.java file and add the package declaration that it relates to in the file. In fact, the only thing the package-info.java file must contain is the package declaration.

package-info.java是一个Java文件,可以添加到任何Java源包中。其目的是为包级别文档和包级别注释提供一个主页。只需创建package-info.java文件,并在文件中添加与其相关的包声明。实际上,package-info.java文件必须包含的唯一内容是包声明。

#1


26  

Summary from the article here

这篇文章摘要

In package-info.java:

@PackageLevelAnnotation
package blammy; // package with a package level annotation.


import blammy.annotation.PackageLevelAnnotation;

In PackageLevelAnnotation.java

package blammy.annotation;

@Retention(RetentionPolicy.CLASS)
@Target(ElementType.PACKAGE)
public @interface PackageLevelAnnotation
{
  // stuff as required.
}

Edit: more package level info. Here is a link to the package chapter in the Java Language Spec: packages

编辑:更多包级别信息。以下是Java语言规范包中的包章节的链接

#2


38  

In eclipse

Since package-info.java isn't a valid identifier for a class it cannot be created as a class in Eclipse.

由于package-info.java不是类的有效标识符,因此无法在Eclipse中将其创建为类。

I found that when you create a new package there is a check box to check if you want a package-info.java.

我发现当你创建一个新包时,有一个复选框来检查你是否想要一个package-info.java。

To create a package-info.java file in an existing package:

要在现有包中创建package-info.java文件:

  1. Right-click on the package where you want a package-info.java.
  2. 右键单击要包含package-info.java的包。

  3. Select New->Package.
  4. Check the Create package-info.java check box.
  5. 选中Create package-info.java复选框。

  6. Click on Finish.
  7. 单击Finish。

#3


3  

Open explorer, go to src/your package folder.
right click -> Create new textfile: name it package-info.java.

打开资源管理器,转到src /你的包文件夹。右键单击 - >创建新的文本文件:将其命名为package-info.java。

Go back to eclipse and edit and add the desired content.

返回eclipse并编辑并添加所需内容。

#4


2  

The package-info.java is a Java file that can be added to any Java source package. Its purpose is to provide a home for package level documentation and package level annotations. Simply create the package-info.java file and add the package declaration that it relates to in the file. In fact, the only thing the package-info.java file must contain is the package declaration.

package-info.java是一个Java文件,可以添加到任何Java源包中。其目的是为包级别文档和包级别注释提供一个主页。只需创建package-info.java文件,并在文件中添加与其相关的包声明。实际上,package-info.java文件必须包含的唯一内容是包声明。