Maven:从url下载文件 [英] Maven: downloading files from url

查看:415
本文介绍了Maven:从url下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在maven生命周期中从http下载一些文件吗?任何插件?

解决方案

如果该文件是Maven依赖项,则可以使用 Maven Dependency Plugin ,它有一个 获取 目标。



对于任何文件,您可以使用Antrun插件调用Ant的获取任务



另一个选项是 maven-download-plugin ,它已被精确创建,以促进这种事情。这不是非常积极的开发,文档只提到了一个神器目标,它和依赖关系完全相同:get 但是.. 如果你看看源代码,你会发现它有一个可以完成这项工作的WGET mojo。



使用它这在任何POM:

 < plugin> 
< groupId> com.googlecode.maven-download-plugin< / groupId>
< artifactId> download-maven-plugin< / artifactId>
< version> 1.3.0< / version>
<执行次数>
<执行>
<! - wget目标实际上默认绑定到这个阶段 - >
<阶段>过程资源< /阶段>
<目标>
< goal> wget< / goal>
< /目标>
<配置>
< url> http:// url / to / some / file< / url>
< outputFileName> foo.bar< / outputFileName>
<! - 默认目标位置,仅用于演示参数 - >
< outputDirectory> $ {project.build.directory}< / outputDirectory>
< / configuration>
< /执行>
< /执行次数>
< / plugin>

这个插件的主要优点是缓存下载和检查签名,比如MD5。



请注意,这个答案已经大量更新,以反映评论中所述的插件变化。 b $ b

Can I download some files from http while maven lifecycle? any plugin?

解决方案

If the file is a Maven dependency, you could use the Maven Dependency Plugin which has a get goal.

For any file, you could use the Antrun plugin to call Ant's Get task.

Another option would be the maven-download-plugin, it has been precisely created to facilitate this kind of things. It's not very actively developed and the documentation only mentions an artifact goal that does exactly the same thing as dependency:get but.. If you look at the sources, you'll see that is has a WGet mojo that will do the job.

Use it like this in any POM:

<plugin>
  <groupId>com.googlecode.maven-download-plugin</groupId>
  <artifactId>download-maven-plugin</artifactId>
  <version>1.3.0</version>
  <executions>
    <execution>
      <!-- the wget goal actually binds itself to this phase by default -->
      <phase>process-resources</phase>
      <goals>
        <goal>wget</goal>
      </goals>
      <configuration>
        <url>http://url/to/some/file</url>
        <outputFileName>foo.bar</outputFileName>
        <!-- default target location, just to demonstrate the parameter -->
        <outputDirectory>${project.build.directory}</outputDirectory>
      </configuration>
    </execution>
  </executions>
</plugin>

Key benefits of this plugin are caching of the download and checking against a signature, such as MD5.

Note that this answer has been heavily updated to reflect changes in the plugin as noted in the comments.

这篇关于Maven:从url下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆