2015-09-14 34 views
1

我正在構建自定義標籤,我希望它可以作爲單個jar文件提供。我似乎遇到了tld文件的問題,以及如何將它包含到構建過程中。什麼是在Maven項目中TLD文件的正確/推薦位置

我目前的文件夾結構:pom.xml中的

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

部分(.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中,額外分支是在「項目」視圖中創建的。不用說這真的看起來很糟糕。 enter image description here
  3. 我需要在pom.xml中的條目,因爲否則.tld文件將不會包含在jar中。

第一個問題: 是否有Maven的一些設置,其中將包括默認${basedir}/src/main/resources/META-INF文件夾的內容?


替代做法:pom.xml中的

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

部分(.tld文件不包含到默認的構建過程)

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

這種做法有pom.xml沒有長路徑,在Netbeans p中沒有創建額外的分支roject視圖,但我不確定該位置是否正確。我找到了很多這樣的鏈接,如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

第二個問題: 什麼是.tld文件Maven項目內的正確/推薦位置?請注意,我詢問項目的位置,而不是在創建的jar文件中的位置(它必須是META-INF,我知道)。

回答

0

我想我已經成功地解決我的問題,這裏是答案:

第一個問題:是否有Maven的一些設置,其中將包括默認${basedir}/src/main/resources/META-INF文件夾的內容?

我花了時間公平ammount的搜索互聯網,我可以說沒有沒有,你需要寫在pom.xml條目,將做到這一點

第二個問題:什麼是Maven的項目中的TLD文件的正確/推薦位置?

看來正確或推薦的位置畢竟是src/main/resources/META-INF

解決我的問題: 我在<resources>定義我.tld文件的複製上<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> 

我已經感動的是資源進入maven-resources-plugin<resources>。目錄的路徑仍然很長,但這是我可以生活的東西,尤其是那種方法,我可以讓我的.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> 
相關問題