web-dev-qa-db-ja.com

Mavenで依存関係を解凍する

私はmavenに次の依存関係があります

<dependency>
  <groupId>org.hyperic</groupId>
  <artifactId>sigar-dist</artifactId>
  <version>1.6.5.132</version>
  <type>Zip</type>
</dependency>

これはsigar-dist-1.6.5.132.Zipリポジトリにあります。私はこれを見てきました ここでの質問 ですが、それでもまだ機能させることができません。

Sigar-dist.Zipを解凍して、プロジェクトのディレクトリにコンテンツを配置するにはどうすればよいですか?それを機能させるために私がしなければならないmvn呼び出しは何ですか?

25
Shervin Asgari

あなたはdependencies:unpack-dependenciesでそれを行うことができます:

<plugin>
    <groupId>org.Apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>2.2</version>
    <executions>
      <execution>
        <id>unpack-sigar</id>
        <phase>package<!-- or any other valid maven phase --></phase>
        <goals>
          <goal>unpack-dependencies</goal>
        </goals>
        <configuration>
          <includeGroupIds>org.hyperic</includeGroupIds>
          <includeArtifactIds>sigar-dist</includeArtifactIds>
          <outputDirectory>
             ${project.build.directory}/wherever/you/want/it
             <!-- or: ${project.basedir}/wherever/you/want/it -->
          </outputDirectory>
        </configuration>
      </execution>
    </executions>
</plugin>

参考:

39

@Sean Patrick Floydからの回答のフォローアップ

これは、Tomcatをダウンロードして解凍するための最後のpom.xmlです。

<project xmlns="http://maven.Apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.Apache.org/POM/4.0.0 http://maven.Apache.org/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>org.koushik.javabrains</groupId>
    <artifactId>Tomcat</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>Tomcat</name>

    <properties>
        <Tomcat.version>8.0.27</Tomcat.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.Apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.8</version>
                <executions>
                    <execution>
                        <id>unpack-Tomcat</id>
                        <phase>package</phase>
                        <goals>
                            <goal>unpack-dependencies</goal>
                        </goals>
                        <configuration>
                            <includeGroupIds>org.Apache.Tomcat</includeGroupIds>
                            <includeArtifactIds>Tomcat</includeArtifactIds>
                            <outputDirectory>
                                ${project.build.directory}
                                <!-- or: ${project.basedir}/wherever/you/want/it -->
                            </outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.Apache.Tomcat</groupId>
            <artifactId>Tomcat</artifactId>
            <version>${Tomcat.version}</version>
            <type>Zip</type>
        </dependency>
    </dependencies>
</project>
4
Andrzej Rehmann