<dependencies> <dependency> <groupId>org.ow2.util.annotation</groupId> <artifactId>annotation-processor</artifactId> <version>1.0.0</version> <scope>provided</scope> </dependency> </dependencies> @CustomAnnotation("example") public class MyClass { // Class implementation } @SupportedAnnotationTypes("org.example.CustomAnnotation") public class CustomAnnotationProcessor extends AbstractProcessor { @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { for (Element element : roundEnv.getElementsAnnotatedWith(CustomAnnotation.class)) { CustomAnnotation annotation = element.getAnnotation(CustomAnnotation.class); String value = annotation.value(); // Generate code using the annotation value // ... } return true; } } <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <annotationProcessorPaths> <path> <groupId>org.ow2.util.annotation</groupId> <artifactId>annotation-processor</artifactId> <version>1.0.0</version> </path> </annotationProcessorPaths> </configuration> </plugin> </plugins> </build>


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