You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Maven从jFrog仓库下载tar.Z文件?求解决方法

用Maven下载tar.Z文件的几种方法

1. 从Maven仓库下载(文件已上传至仓库)

如果目标tar.Z文件是作为Maven构件存在于公共或私有仓库中,直接在pom.xml中添加依赖并指定文件类型:

<dependencies>
    <dependency>
        <groupId>你的构件组ID</groupId>
        <artifactId>你的构件ID</artifactId>
        <version>版本号</version>
        <type>tar.Z</type>
        <!-- 若构件有分类器(如平台区分),添加以下配置 -->
        <!-- <classifier>linux-x86_64</classifier> -->
    </dependency>
</dependencies>

Maven会自动将文件下载到本地仓库(默认路径:~/.m2/repository)。如果需要将文件复制到项目指定目录,搭配maven-dependency-plugin:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>3.6.1</version>
            <executions>
                <execution>
                    <id>copy-tar-z</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>你的构件组ID</groupId>
                                <artifactId>你的构件ID</artifactId>
                                <version>版本号</version>
                                <type>tar.Z</type>
                                <outputDirectory>${project.build.directory}/downloads</outputDirectory>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

执行mvn package后,文件会被复制到target/downloads目录。

2. 从外部URL下载(文件不在Maven仓库)

如果文件存放在外部HTTP/HTTPS地址,可使用download-maven-plugin直接拉取:

<build>
    <plugins>
        <plugin>
            <groupId>com.googlecode.maven-download-plugin</groupId>
            <artifactId>download-maven-plugin</artifactId>
            <version>1.6.8</version>
            <executions>
                <execution>
                    <id>download-external-tar-z</id>
                    <phase>package</phase>
                    <goals>
                        <goal>wget</goal>
                    </goals>
                    <configuration>
                        <url>https://example.com/path/to/target/file.tar.Z</url>
                        <outputDirectory>${project.build.directory}/downloads</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

3. 用系统命令辅助下载

如果上述Maven插件不满足需求,可通过exec-maven-plugin调用系统的curl或wget命令:

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>3.1.0</version>
            <executions>
                <execution>
                    <id>download-with-curl</id>
                    <phase>package</phase>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                    <configuration>
                        <executable>curl</executable>
                        <arguments>
                            <argument>-o</argument>
                            <argument>${project.build.directory}/downloads/file.tar.Z</argument>
                            <argument>https://example.com/path/to/target/file.tar.Z</argument>
                        </arguments>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

注意事项

  • 若下载地址需要身份认证,需在settings.xml中配置服务器凭证,或在插件中添加认证参数。
  • 确保使用的Maven插件版本与你的Maven版本兼容。

内容的提问来源于stack exchange,提问作者Mitu Mallick

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 03:30:45