Currently, I know how to do this kind of filtering using Maven:
pom.xml
<properties>
<foo>bar</foo>
</properties>
app.properties
foo=${foo}
But is it possible to do that kind of filtering, using Maven, Spring or any tool else?
MyClass.java
@MyAnnotation("${foo}") // ${foo} should get replaced at compile time
public void getData() {
return data;
}
Also, the maven supports a large scale of built-in properties. Here over this article, we will discuss all these kind of properties supported by maven. What are the types of properties in Maven? Maven supports a great set of property references. In pom.xml it can get the os configured properties, Java properties.
This annotation is processed by the container at deployment time, and the corresponding filter applied to the specified URL patterns, servlets, and dispatcher types. The classes annotated with @WebFilter must implement javax.servlet.Filter.
So unless you have configured the encoding parameter in Maven Resources Plugin explicitly this is what you get. When the Properties class is used to read and write properties files they require that the properties files use ISO-8859-1 encoding. This is still the case for Java 11, as can be seen in the API documentation for the Properties class.
Java defines seven built-in annotations. Four are imported from java.lang.annotation: @Retention, @Documented, @Target, and @Inherited. It is a marker annotation. It indicates that a declaration is obsolete and has been replaced by a newer form.
Have you tried using an execution of the resource plugin. You can point it at your Java source and use its normal filtering, as far as I know.
http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html
<properties>
<my.name>chad</my.name>
<java.property>//comment</java.property>
</properties>
<build>
<sourceDirectory>target/processed-source/java</sourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<filtering>true</filtering>
<targetPath>../processed-source/java</targetPath>
</resource>
</resources>
</build>
So, the first thing is that you route the processed java source into a special folder in the target directory. Next, you have to reconfigure the compiler plugin to NOT compile the unfiltered source, and, instead, compile the new source. Note, as with all things maven, you can configure a lot more than this.
This blog entry is useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With