maven - IntelliJ 的 Maven 过滤支持如何工作?

标签 maven intellij-idea

我注意到,当您将 Maven 项目配置为使用属性过滤时,属性过滤似乎在非 Maven IntelliJ“制作”期间也有效。这意味着 Jetty/Tomcat/GWT/Glassfish 的 IntelliJ 运行配置仍将支持您的 maven 资源过滤。

因此,如果我将此添加到我的 pom.xml :

 <build>
     <resources>
         <resource>
             <directory>src/main/resources</directory>
             <filtering>true</filtering>
             <includes>
                 <include>**/*.properties</include>
                 <include>**/persistence.xml</include>
             </includes>
         </resource> ....

它应该在任何 intellij 运行配置开始之前过滤我的 properties 和 peristence.xml 文件中的任何属性。这对于交换 JDBC 引用或文件系统参数非常有用。

我遇到的唯一问题是 IntelliJ 似乎只尊重 src/main/resources 中的过滤,即使我将 pom.xml 更改为其他目录的第二个条目(即:src/integrationtest/resources)。

这一切似乎都是“自动的”。那么它是如何工作的,我可以在哪里(如果有的话)配置它?

最佳答案

IntelliJ IDEA's Make features are capable of filtering Maven resources. However, IntelliJ IDEA yet does not support filtering web resources.



来源:http://www.jetbrains.com/idea/webhelp/maven.html#compile
虽然在整个 intellij webhelp 中没有关于这种支持的更多细节,所以我想它应该像 maven 的 process-resources 阶段一样工作。

您遇到的问题可能是由目录 src/integrationtest/resources 引起的。不遵循 Maven 约定。
如果您这样做,也许它会起作用:
  • 让它src/test/resources/integrationtest/

  • 或者
  • 配置 Maven 以尊重 src/integrationtest作为测试源(但如果 integrationtest 不是众所周知的约定,它将违反 maven 的 COC 规则)

  • 或者
  • 如果您想强调 integrationtest 的隔离,请使其成为另一个 maven(子)模块

  • 至于过滤目录不同于src/main/resources : 过滤 src/main/webapp/META-INF为我开箱即用。
    (Maven 3.0.4,Intellij 12.1.4)

    关于maven - IntelliJ 的 Maven 过滤支持如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10036400/

    相关文章:

    maven 程序集,避免 zip 文件中的完整路径?

    maven - 在没有我自己的存储库的情况下使用 Maven

    java - 每次重新加载 pom 时停止 IntelliJ IDEA 切换 java 语言级别(或更改默认项目语言级别)

    unit-testing - Java 测试停留在使用 TestNG 在 Intellij 中实例化测试

    java - Intellij 中的使用 API 错误

    java - Gradle 中出现 ModuleVersionNotFoundException 的原因是什么?

    java - 如何处理打包到jar的maven项目中的资源路径

    tomcat - 如何使用 IntelliJ 和 Tomcat 热部署 Vaadin

    intellij-idea - 构建 IntelliJ 的 Artifacts 键盘快捷键

    Spring Cloud Config Server 在运行 main() 时不强制执行 BASIC 身份验证