I’m building custom tag which I want make available as single jar file. I seem to be having a problem with tld file and how to include it into build process.
My current folder structure:
src
license.md
main
java
my.package
class1.java
class2.java
resources
META-INF
customtag.tld
Part of pom.xml (.tld
file is not included into build process by default)
<resources>
<resource>
<directory>${basedir}/src/main/resources/META-INF</directory>
<targetPath>META-INF</targetPath>
<filtering>true</filtering>
<includes>
<include>customtag.tld</include>
</includes>
</resource>
The above works but:
First Question:
Is there some setting in Maven which will include ${basedir}/src/main/resources/META-INF
folder contents by default?
Alternative approach:
src
license.md
ckeditor.tld
main
java
my.package
class1.java
class2.java
Part of pom.xml (.tld
file is not included into build process by default)
<resource>
<directory>${basedir}</directory>
<targetPath>META-INF</targetPath>
<filtering>true</filtering>
<includes>
<include>customtag.tld</include>
</includes>
</resource>
With that approach there is no long path in pom.xml
, no extra branch created in Netbeans project view but I’m not sure if that location is correct. I have found many links like this one Where do I put the .tld file so that the resulting JAR file built with maven2 is properly packaged? which say that tld files in project code should be put into src/main/resources/META-INF
.
Second Question:
What is the correct/recommended location of the .tld
file inside the Maven project? Please note that I’m asking about project location and not location in created jar file (it has to be META-INF
, I know that).
I think I have managed to fix my problem and here are the answers:
First Question: Is there some setting in Maven which will include
${basedir}/src/main/resources/META-INF
folder contents by default?
I have spent fair ammount of time searching the internet and I can say No there is not, you need to write entries in pom.xml
that will do that.
Second Question: What is the correct/recommended location of the tld file inside the Maven project?
It seems that correct or recommended location is src/main/resources/META-INF
after all.
Solution to my problem:
I had copying of my .tld
file defined in <resources>
on <build>
level.
<resources>
<resource>
<directory>${basedir}/src/main/resources/META-INF</directory>
<targetPath>META-INF</targetPath>
<filtering>true</filtering>
<includes>
<include>customtag.tld</include>
</includes>
</resource>
<resources>
I have moved that resource into <resources>
of maven-resources-plugin. The path to directory is still long but this is something I can live with especially that with that approach I can keep my .tld
file in src/main/resources/META-INF
and that annoying extra branch in Netbeans Project View is now gone.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/resources/META-INF</directory>
<targetPath>META-INF</targetPath>
<filtering>true</filtering>
<includes>
<include>customtag.tld</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>