gpt4 book ai didi

java - Maven 项目中 TLD 文件的正确/推荐位置是什么

转载 作者:行者123 更新时间:2023-11-30 10:57:34 29 4
gpt4 key购买 nike

我正在构建自定义标签,我希望将其作为单个 jar 文件提供。我似乎遇到了 tld 文件以及如何将其包含到构建过程中的问题。

我当前的文件夹结构:

src
license.md
main
java
my.package
class1.java
class2.java
resources
META-INF
customtag.tld

部分pom.xml(.tld文件默认不包含在构建过​​程中)

<resources>
<resource>
<directory>${basedir}/src/main/resources/META-INF</directory>
<targetPath>META-INF</targetPath>
<filtering>true</filtering>
<includes>
<include>customtag.tld</include>
</includes>
</resource>

上面的工作但是:

  1. 我觉得不太好,尤其是目录路径
  2. 在 NetBeans 中,额外的分支是在项目 View 中创建的。不用说这看起来真的很糟糕。 enter image description here
  3. 我需要 pom.xml 中的该条目,否则 .tld 文件将不会包含在 jar 中。

第一个问题:Maven 中是否有一些设置默认包含 ${basedir}/src/main/resources/META-INF 文件夹内容?


替代方法:

src
license.md
ckeditor.tld
main
java
my.package
class1.java
class2.java

部分pom.xml(.tld文件默认不包含在构建过​​程中)

<resource>
<directory>${basedir}</directory>
<targetPath>META-INF</targetPath>
<filtering>true</filtering>
<includes>
<include>customtag.tld</include>
</includes>
</resource>

通过这种方法,pom.xml 中没有长路径,也没有在 Netbeans 项目 View 中创建额外的分支,但我不确定该位置是否正确。我找到了很多这样的链接 Where do I put the .tld file so that the resulting JAR file built with maven2 is properly packaged?其中表示项目代码中的 tld 文件应放入 src/main/resources/META-INF

第二个问题:Maven 项目中 .tld 文件的正确/推荐位置是什么?请注意,我问的是项目位置,而不是创建的 jar 文件中的位置(它必须是 META-INF,我知道)。

最佳答案

我想我已经设法解决了我的问题,以下是答案:

First Question: Is there some setting in Maven which will include ${basedir}/src/main/resources/META-INF folder contents by default?

我花了相当多的时间在互联网上搜索,我可以说不,没有,你需要在pom.xml中写条目这将做到这一点

Second Question: What is the correct/recommended location of the tld file inside the Maven project?

似乎正确或推荐的位置是 src/main/resources/META-INF毕竟。

我的问题的解决方案:我复制了我的 .tld <resources> 中定义的文件在 <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>

我已将该资源移至 <resources>maven-resources-plugin .目录的路径仍然很长,但这是我可以接受的,尤其是通过这种方法我可以保留我的 .tld。文件在 src/main/resources/META-INF Netbeans Project View 中那个烦人的额外分支现在消失了。

<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>

关于java - Maven 项目中 TLD 文件的正确/推荐位置是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32568966/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com