【问题标题】:Maven doesn't save any files in the target/classes directoryMaven 不会在 target/classes 目录中保存任何文件
【发布时间】:2014-01-21 19:24:48
【问题描述】:

此处的文档 (http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html) 告诉我,我应该在 target/classes 目录中看到过滤后的文件。当我运行compilepackage 时,在这两种情况下都没有在target 目录中生成classes 目录,因此在那个不存在的目录中也没有文件。 (我认为它们可能是在 compile 期间创建的,但随后作为 package 的副产品被删除。)

这是我的目录结构。我有一个用于父模块的主 pom.xml 和几个带有自己 pom.xml 文件的子模块,每个模块下都有 src 目录。

mexp/
  mexp-model/
    src/main/java/com/pronto/…
    pom.xml

  mexp-services/
    src/main/java/com/pronto/…
    pom.xml

  mexp-webapp/
    src/
      main/
        java/
          com/
            pronto/
              mexp/
                action/
                  LoginFormAction.java
    pom.xml

  pom.xml

这是我的根 pom.xml 中的 build 部分:

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
    <filters>
        <filter>${profile.directory}/${env}/tokens.properties</filter>
    </filters>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
                <compilerArgument>-g</compilerArgument>
            </configuration>
        </plugin>
    </plugins>
</build>

FWIW,我正在使用 Maven 3.1.1 和 Java 1.6.0_65,IntelliJ 11.1.5。

我正在尝试调试过滤,所以我真的很想查看那些生成的文件。任何帮助,将不胜感激。谢谢。

已编辑:我将此添加到我的 mexp-webapp/pom.xml:

<plugins>
    <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.6</version>
    </plugin>
    ...
</plugins>

当我在调试时从命令行运行它时,这就是它所说的。但是在它声称正在过滤文件的目录中没有找到文件(请原谅我的结尾介词)。

[INFO] Copying 8 resources
[DEBUG] file apsmonitoring.properties has a filtered file extension
[DEBUG] filtering /Volumes/xyz/mexp-removeDAL/mexp-webapp/src/main/resources/apsmonitoring.properties to /Volumes/xyz/mexp-removeDAL/mexp-webapp/target/classes/apsmonitoring.properties
[DEBUG] file config.xml has a filtered file extension
[DEBUG] filtering /Volumes/xyz/mexp-removeDAL/mexp-webapp/src/main/resources/config.xml to /Volumes/xyz/mexp-removeDAL/mexp-webapp/target/classes/config.xml
[DEBUG] file email-configuration.properties has a filtered file extension
[DEBUG] filtering /Volumes/xyz/mexp-removeDAL/mexp-webapp/src/main/resources/email-configuration.properties to /Volumes/xyz/mexp-removeDAL/mexp-webapp/target/classes/email-configuration.properties
[DEBUG] file log4j.real.xml has a filtered file extension
[DEBUG] filtering /Volumes/xyz/mexp-removeDAL/mexp-webapp/src/main/resources/log4j.real.xml to /Volumes/xyz/mexp-removeDAL/mexp-webapp/target/classes/log4j.real.xml
[DEBUG] file log4j.xml has a filtered file extension
[DEBUG] filtering /Volumes/xyz/mexp-removeDAL/mexp-webapp/src/main/resources/log4j.xml to /Volumes/xyz/mexp-removeDAL/mexp-webapp/target/classes/log4j.xml
[DEBUG] file mexp.properties has a filtered file extension
[DEBUG] filtering /Volumes/xyz/mexp-removeDAL/mexp-webapp/src/main/resources/mexp.properties to /Volumes/xyz/mexp-removeDAL/mexp-webapp/target/classes/mexp.properties
[DEBUG] file mexp_globals.properties has a filtered file extension
[DEBUG] filtering /Volumes/xyz/mexp-removeDAL/mexp-webapp/src/main/resources/mexp_globals.properties to /Volumes/xyz/mexp-removeDAL/mexp-webapp/target/classes/mexp_globals.properties
[DEBUG] file mexp_messages.properties has a filtered file extension
[DEBUG] filtering /Volumes/xyz/mexp-removeDAL/mexp-webapp/src/main/resources/mexp_messages.properties to /Volumes/xyz/mexp-removeDAL/mexp-webapp/target/classes/mexp_messages.properties
[DEBUG] no use filter components
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.509s
[INFO] Finished at: Tue Jan 21 15:10:28 EST 2014
[INFO] Final Memory: 4M/81M
[INFO] ------------------------------------------------------------------------

【问题讨论】:

  • 你是使用IDE生成输出还是命令行?要尝试解决 Maven 特定问题,我建议您使用命令行。
  • 查看更多内容;我一直在使用两者,但我添加了在命令行上运行它的输出。
  • 已解决。显然,intelliJ 隐藏了目标/类目录及其所有内容。当我从命令行查看时,我可以看到我所有的属性文件,按照承诺完美过滤和复制。但更重要的是,我什至不需要专门使用 maven-resources-plugin,只要存在&lt;build&gt;&lt;resources&gt;&lt;resource&gt;...&lt;filtering&gt;true&lt;/filtering&gt;&lt;/resource&gt;&lt;/resources&gt;...,maven 本身就能够很好地插入值。 HTH 别人。

标签: java maven intellij-idea maven-3


【解决方案1】:

IntelliJ 问题跟踪器上有一个关于此的问题:IDEA-75538 运行 Maven 构建时不应自动隐藏输出目录

建议的解决方案是这样的:

有一个选项可以禁用排除“目标”。请参阅设置 -> Maven -> 导入 -> “排除构建目录”

【讨论】:

  • 我对此抱有希望,但我在 Maven -> Importing 下的 intelliJ 设置中没有看到该选项。
  • 尝试跟进该问题。以我的经验,JetBrains 的人确实会对这些问题做出反应。该问题是针对旧版本的 IntelliJ 提交的,该设置可能已(重新)移动,可能已重命名。
  • 我对该问题添加了评论 - 感谢您提供指向它的指针。我实际上确实看到了target 目录,但没有看到它下面的classes 目录(显然也没有看到classes 目录中的文件)。所以他们可能认为他们“解决”了这个问题......
猜你喜欢
  • 2015-03-17
  • 2014-02-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-16
  • 1970-01-01
  • 2012-09-08
相关资源
最近更新 更多