【问题标题】:Maven including unfiltered resource file in jar rather than what is in target/classesMaven 在 jar 中包含未过滤的资源文件,而不是目标/类中的内容
【发布时间】:2012-02-15 07:18:23
【问题描述】:

鉴于,

Apache Maven 3.0.3 和一个 src/main/resources/application.properties 文件

 project.root=${basedir}

和一个 pom.xml 文件

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

当我运行“mvn clean package”时,我得到一个带有过滤功能的 target/classes/application.properties 文件

project.root=/path/to/MyProject

但是,jar 中包含的 application.properties 文件没有被过滤。

project.root=${basedir}

为什么jar中包含的application.properties文件没有被过滤?根据documentation,来自目标/类的过滤属性文件应该包含在 jar 中。

【问题讨论】:

  • 我按照您的描述进行了测试,它对我有用。奇怪的。您是否在 pom.xml 中配置了 maven-jar-plugin?如果是这样,我想看看。
  • 谢谢,@BenjaminLinus。对于我的设置,问题出在 maven-bundle-plugin 的配置中。我需要添加&lt;Include-Resources&gt;{maven-resources}&lt;/Include-Resources&gt;
  • 我没有使用maven-bundle-plugin,但是多模块maven项目中存在问题。资源:资源产生过滤文件,但干净的包产生带有未过滤文件的jar!知道如何克服吗?

标签: maven resources properties jar filtering


【解决方案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>

【讨论】:

    【解决方案2】:

    自助服务。

    需要加&lt;Include-Resources&gt;{maven-resources}&lt;/Include-Resources&gt;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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-02
      • 1970-01-01
      • 2014-01-14
      • 1970-01-01
      • 2010-11-20
      • 2013-07-07
      • 2023-03-04
      • 1970-01-01
      相关资源
      最近更新 更多