It so complicated for me, so i probably will can't to ask normally question, but i will try...So, i want to compile the .html file using command "mvn clean compile". I also have two custom quite similar annotations (@HtmlForm (for classes) and @HtmlInput (for fields)) looks like: @HtmlForm:
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
public @interface HtmlForm {
String fileName();
String action();
String method();
}
And one annotated class:
@HtmlForm(fileName = "user_form.html", action = "/users", method = "post")
public class UserForm {
@HtmlInput(type = "text", name = "first_name", placeholder = "Enter First Name")
private String firstName;
@HtmlInput(type = "text", name = "last_name", placeholder = "Enter Last Name")
private String lastName;
@HtmlInput(type = "password", name = "password", placeholder = "Enter Password")
private String password;
}
my .pom file included dependencies on auto-service (seems to declare processor), on compile-plugin and reflection-util. I tried to write some custom annotation processor, but here few myknowleges are ended, and this is all, that I could to do:
@SupportedAnnotationTypes({"HtmlForm", "HtmlInput"})
@AutoService(Processor.class)
public class HtmlProcesser extends AbstractProcessor{
@Override
public boolean process(Set<? extends TypeElement> set, RoundEnvironment roundEnv) {
Set<? extends Element> annotatedElements = null;
for (TypeElement annotation : set) {
annotatedElements = roundEnv.getElementsAnnotatedWith(HtmlForm.class);
if (!annotatedElements.isEmpty()) {
try {
FileObject file = processingEnv.getFiler()
.createResource(StandardLocation.CLASS_OUTPUT, "","user_form.html");
PrintWriter out = new PrintWriter(file.openWriter());
out.print("sometext!!!!!");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
return true;
}
}
At first, I tried to create "user_form.html" file and write "sometext!!!" into it, but this file is not created. I also includes "user-form.html" into mvn-compile-plugin and it's does not help. What should I do?
Updade (my .pom-file):
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>Annotation</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
</dependency>
<dependency>
<groupId>de.cronn</groupId>
<artifactId>reflection-util</artifactId>
<version>2.14.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>