【问题标题】:What is the correct/recommended location of TLD file in Maven projectMaven项目中TLD文件的正确/推荐位置是什么
【发布时间】:2015-12-10 16:48:54
【问题描述】:

我正在构建自定义标签,我希望将其作为单个 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 中,在项目视图中创建了额外的分支。不用说这看起来真的很糟糕。
  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 项目视图中没有创建额外的分支,但我不确定该位置是否正确。我发现了很多类似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,我知道)。

【问题讨论】:

    标签: java eclipse netbeans maven-2 jsp-tags


    【解决方案1】:

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

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

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

    第二个问题: tld 文件在 Maven 项目中的正确/推荐位置是什么?

    看来正确或推荐的位置毕竟是src/main/resources/META-INF

    解决我的问题: 我在&lt;build&gt;level 上复制了&lt;resources&gt; 中定义的.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>
    <resources>
    

    我已将该资源移至 &lt;resources&gt;maven-resources-plugin。目录的路径仍然很长,但这是我可以忍受的,尤其是通过这种方法,我可以将我的 .tld 文件保留在 src/main/resources/META-INF 中,并且 Netbeans 项目视图中烦人的额外分支现在已经消失了。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-30
      • 1970-01-01
      • 2021-06-12
      • 1970-01-01
      • 1970-01-01
      • 2012-12-18
      相关资源
      最近更新 更多