【问题标题】:Finding files by pattern in Maven在 Maven 中按模式查找文件
【发布时间】:2020-12-13 05:11:14
【问题描述】:

我需要预处理 Java Maven 项目中的一些资源文件 (*.xsl)。 我发现exec-maven-plugin 能够执行shell 命令,并认为我可以分两步完成:

  1. 匹配文件列表并将其写入文件
  2. 启动一个 Java 程序,对列表中的每个文件进行预处理

但是,我尝试执行的 find 命令没有得到任何输出。 POM 中的插件配置如下所示:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>3.0.0</version>
    <executions>
        <execution>
            <id>inline-xml-entities</id>
            <phase>generate-resources</phase>
            <configuration>
                <executable>find</executable>
                <useMavenLogger>true</useMavenLogger>
                <outputFile>xsl-files.txt</outputFile>
                <arguments>
                    <argument>./src/main/webapp/static/com/atomgraph/</argument>
                    <argument>-type</argument>
                    <argument>f</argument>
                    <argument>-name</argument>
                    <argument>'*.xsl'</argument>
                </arguments>
            </configuration>
            <goals>
                <goal>exec</goal>
            </goals>
        </execution>
    </executions>
</plugin>

我可以在mvn clean install -X 日志中看到命令被执行:

[DEBUG] Executing command line: [find, ./src/main/webapp/static/com/atomgraph/, -type, f, -name, '*.xsl']

xsl-files.txt 文件已创建,但它是空的:/

如果我转到基于项目的项目并手动执行find ./src/main/webapp/static/com/atomgraph/ -type f -name '*.xsl',我会按预期得到一个 .xsl 文件列表:

./src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/bootstrap/2.3.2/admin/acl/imports/acl.xsl
./src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/bootstrap/2.3.2/admin/acl/layout.xsl
./src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/bootstrap/2.3.2/admin/layout.xsl
...

我错过了什么?

【问题讨论】:

    标签: java bash shell maven exec-maven-plugin


    【解决方案1】:

    这似乎奏效了:

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
            <execution>
                <id>find-xsl-files</id>
                <phase>generate-resources</phase>
                <configuration>
                    <executable>find</executable>
                    <workingDirectory>src/main/webapp/static/com/atomgraph/</workingDirectory>
                    <outputFile>xsl-files.txt</outputFile>
                    <commandlineArgs>. -type f -name '*.xsl'</commandlineArgs>
                </configuration>
                <goals>
                    <goal>exec</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    

    【讨论】:

      猜你喜欢
      • 2021-09-06
      • 2017-02-18
      • 2012-03-06
      • 2012-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多