2012-01-20 12 views
2

何であるか、Mavenのは瓶でフィルタリングされていないリソースファイルを含むのではなく、ターゲット/クラスで考えると

のApache Mavenの3.0.3およびSRC /メイン/リソース/ application.propertiesが

project.root=${basedir} 

によるファイルと

<build> 
    <resources> 
    <resource> 
     <directory>src/main/resources</directory> 
     <filtering>true</filtering> 
    </resource> 
    </resources> 
... 

とpom.xmlファイルI "はMVNクリーンパッケージ" を実行して、私はターゲット/クラスを取得/ application.propertiesは、フィルタリングを使用してファイル

project.root=/path/to/MyProject 

ただし、jarに含まれるapplication.propertiesファイルはフィルタリングされていません。

project.root=${basedir} 

なぜフィルタリングされないjarファイルに含まれているapplication.propertiesファイルがありますか? documentationによれば、ターゲット/クラスからのフィルタリングされたプロパティファイルは、ジャーに含まれるべきである。

+0

これを説明したとおりにテストしたところ、私にとってはうまくいきました。奇妙な。 pom.xmlにmaven-jar-pluginを設定しましたか?もしそうなら、私はそれを見たいと思います。 – BenjaminLinus

+0

ありがとう、@BenjaminLinus。私のセットアップでは、問題はmaven-bundle-pluginの設定にありました。 ' {maven-resources}'を追加する必要がありました。 –

+0

私はmaven-bundle-pluginを使用していませんが、マルチモジュールのmavenプロジェクトに問題があります。 resources:リソースはフィルタリングされたファイルを生成しますが、クリーンなパッケージはフィルタされていないファイルを含むjarファイルを生成します。 どのように克服するか考えていますか? – harvyS

答えて

1

セルフサービス。

<Include-Resources>{maven-resources}</Include-Resources>maven-bundle-pluginに設定する必要があります。

 <plugin> 
      <groupId>org.apache.felix</groupId> 
      <artifactId>maven-bundle-plugin</artifactId> 
      <version>1.4.3</version> 
      <extensions>true</extensions> 
      <configuration> 
       <manifestLocation>META-INF</manifestLocation> 
       <instructions> 
        <Include-Resources>{maven-resources}</Include-Resources> 
        <Bundle-SymbolicName>${bundle.symbolicName}</Bundle-SymbolicName> 
        <Bundle-Version>${project.version}</Bundle-Version> 
        <Export-Package>${bundle.namespace}.*;version="${project.version}"</Export-Package> 
        <Import-Package> 
1

この投稿を作成していただきありがとうございます。プラグインの新しいバージョンを使用している可能性がありますので、私のソリューションは少し違って見えます:

<plugin> 
    <groupId>org.apache.felix</groupId> 
    <artifactId>maven-bundle-plugin</artifactId> 
    <version>2.4.0</version> 
    <extensions>true</extensions> 
    <configuration> 
    <instructions> 
     <!-- 
     The plugin must be instructed to retrieve the filtered files from the "target/classes" directory. 
     Otherwise, it will copy the unfiltered versions in "src/main/resources" to the JAR. 
     --> 
     <Include-Resource>{maven-resources}, {filtered-file.properties=target/classes/filtered-file.properties}</Include-Resource> 
    </instructions> 
    </configuration> 
</plugin> 
関連する問題