Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

get - Maven: downloading files from url

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...