使用通配符

时间:2018-04-13 09:32:45

标签: maven file copy wildcard

我试图将文件移动到具有变量(缓存已破坏)部分的现有文件: 应该将file.js复制到现有文件-0123456789abcdef.js(其中最后一部分16个十六进制数字是可变的) copy-rename-maven-plugin会产生一个额外的文件:file - * .js:

<plugin>
  <groupId>com.coderplus.maven.plugins</groupId>
  <artifactId>copy-rename-maven-plugin</artifactId>
  <executions>
    <execution>
      <id>move-file</id>
      <phase>prepare-package</phase>
      <goals>
        <goal>copy</goal>
      </goals>
      <configuration>
        <sourceFile>${project.build.directory}/unpacked/file.js</sourceFile>
        <destinationFile>${project.build.directory}/unpacked/file-*.js</destinationFile>
      </configuration>
    </execution>
  </executions>
</plugin>

我想最终得到一个文件:file-0123456789abcdef.js,其内容为file.js. 一个简单的终端命令可以很容易地做我想要的,但我想避免使用ant插件。 非常感谢帮助!

1 个答案:

答案 0 :(得分:0)

我发现exec-maven-plugin可以与find -exec结合使用:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>exec-maven-plugin</artifactId>
  <executions>
    <execution>
      <id>move-configuration</id>
      <phase>prepare-package</phase>
      <goals>
        <goal>exec</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <executable>find</executable>
    <arguments>
      <argument>${project.build.directory}/unpacked/>
      <argument>-name</argument>
      <argument>file-*.js</argument>
      <argument>-exec</argument>
      <argument>mv</argument>
      <argument>${project.build.directory}/unpacked/file.js</argument>
      <argument>{}</argument>
      <argument>;</argument>
    </arguments>
  </configuration>
</plugin>
相关问题