【问题标题】:maven mojo for unzip folders?用于解压缩文件夹的maven mojo?
【发布时间】:2012-12-12 11:58:11
【问题描述】:

如何编写java程序(mojo)解压特定位置的文件夹? 如果有人帮助我非常感谢,我是 Maven 新手。

/**
    * The Zip archiver.
    * @parameter \
    expression="${component.org.codehaus.plexus.archiver.Archiver#zip}"
    */

    private ZipArchiver zipArchiver;

    /**
    * Directory containing the build files.
    * @parameter expression="${project.build.directory}/Test"
    */

    private File buildDirectory;

    /**
    * Base directory of the project.
    * @parameter expression="${basedir}"
    */

    private File baseDirectory;

【问题讨论】:

    标签: maven unzip mojo


    【解决方案1】:

    您可以像这样使用maven-dependency-plugin

    <project>
       [...]
       <build>
         <plugins>
           <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-dependency-plugin</artifactId>
             <version>2.6</version>
             <executions>
               <execution>
                 <id>unpack</id>
                 <phase>package</phase>
                 <goals>
                   <goal>unpack</goal>
                 </goals>
                 <configuration>
                   <artifactItems>
                     <artifactItem>
                       <groupId>junit</groupId>
                       <artifactId>junit</artifactId>
                       <version>3.8.1</version>
                       <type>jar</type>
                       <overWrite>false</overWrite>
                       <outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
    
                     </artifactItem>
                   </artifactItems>
                    ...
                   <overWriteReleases>false</overWriteReleases>
                   <overWriteSnapshots>true</overWriteSnapshots>
                 </configuration>
               </execution>
             </executions>
           </plugin>
         </plugins>
       </build>
       [...]
     </project>
    

    或者您可以使用truezip-maven-plugin,如下所示:

      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>truezip-maven-plugin</artifactId>
        <version>1.1</version>
        <executions>
          <execution>
            <id>unpack</id>
            <goals>
              <goal>cp</goal>
            </goals>
            <phase>ThePhaseYouLike</phase>
            <configuration>
              <from>${project.build.directory}/WhatEveryArchive.zip</from>
              <to>${project.build.directory}</to>
            </configuration>
          </execution>
        </executions>
      </plugin>
    

    【讨论】:

      【解决方案2】:

      我会使用 maven antrun pluginunzip task

      例如,如果您希望在测试准备期间发生这种情况:

        <build>
          <plugins>
            <plugin>
              <artifactId>maven-antrun-plugin</artifactId>
              <version>1.7</version>
              <executions>
                <execution>
                  <!-- a lifecycle phase to run the unzip-->
                  <phase> process-test-resources</phase> 
                  <configuration>
                    <target>
      
                       <unzip src="${your.source.zip}" dest="${your.dest}"/>
      
                    </target>
                  </configuration>
                  <goals>
                    <goal>run</goal>
                  </goals>
                </execution>
              </executions>
            </plugin>
          </plugins>
        </build>
      

      【讨论】:

        【解决方案3】:

        你是在正确的方式,恰恰相反:

         /**
         * The UnZip archiver.
         * 
         * @parameter expression="${component.org.codehaus.plexus.archiver.UnArchiver#zip}"
         */
        
        private ZipUnArchiver unzipArchiver; 
        

        :)

        【讨论】:

          猜你喜欢
          • 2013-03-09
          • 2010-09-05
          • 1970-01-01
          • 2010-12-14
          • 1970-01-01
          • 2017-02-03
          • 2013-10-30
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多