<dependency> <groupId>jakarta.annotation</groupId> <artifactId>jakarta.annotation-api</artifactId> <version>1.3.5</version> </dependency> @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface MyAnnotation { String value() default ""; } @MyAnnotation("Hello World") public class MyClass { // Class body } @SupportedAnnotationTypes("com.example.MyAnnotation") public class MyAnnotationProcessor extends AbstractProcessor { @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { // Process annotations return true; } } <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <annotationProcessorPaths> <path> <groupId>com.example</groupId> <artifactId>my-annotation-processor</artifactId> <version>1.0.0</version> </path> </annotationProcessorPaths> </configuration> </plugin>


上一篇:
下一篇:
切换中文