0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Apache Maven を使用して jarファイル をダウンロードする方法

Last updated at Posted at 2020-01-01

Apache Mavenを使用してjarファイルをダウンロードする方法を紹介します。

環境

  • jdk 1.8.0_231
  • Apache Maven 3.6.2

ダウンロード方法

以下のコマンドでダウンロード可能。
mvn dependency:get -Dartifact=<groupId>:<artifactId>:<version> -Ddest=<出力先フォルダ>

試しにlogback-core-1.2.3.jarをダウンロードしてみます。

C:\Data\mvn_download>mvn dependency:get -Dartifact=ch.qos.logback:logback-core:1.2.3 -Ddest=./
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:get (default-cli) @ standalone-pom ---
[INFO] Resolving ch.qos.logback:logback-core:jar:1.2.3 with transitive dependencies
[WARNING] destination/dest parameter is deprecated: it will disappear in future version.
[INFO] Copying C:\DK\apache-maven-3.6.2\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar to C:\Data\mvn_download\.
[WARNING] Notice transitive dependencies won't be copied.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.929 s
[INFO] Finished at: 2020-01-01T21:18:30+09:00
[INFO] ------------------------------------------------------------------------

C:\Data\mvn_download>dir
 ドライブ C のボリューム ラベルは Windows です
 ボリューム シリアル番号は F039-627E です

 C:\Data\mvn_download のディレクトリ

2020/01/01  21:45    <DIR>          .
2020/01/01  21:45    <DIR>          ..
2019/12/31  17:36           471,901 logback-core-1.2.3.jar
               1 個のファイル             471,901 バイト
               2 個のディレクトリ  184,504,082,432 バイトの空き領域

C:\Data\mvn_download>

また、以下のコマンドでもダウンロード可能です。

mvn dependency:get -DgroupId=<groupId> -DartifactId=<artifactId> -Dversion=<version> -Ddest=<出力先フォルダ>

今度は試しにlogback-classic-1.2.3.jarをダウンロードしてみます。

C:\Data\mvn_download>mvn dependency:get -DgroupId=ch.qos.logback -DartifactId=logback-classic -Dversion=1.2.3 -Ddest=./
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:get (default-cli) @ standalone-pom ---
[INFO] Resolving ch.qos.logback:logback-classic:jar:1.2.3 with transitive dependencies
[WARNING] destination/dest parameter is deprecated: it will disappear in future version.
[INFO] Copying C:\DK\apache-maven-3.6.2\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar to C:\Data\mvn_download\.
[WARNING] Notice transitive dependencies won't be copied.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.139 s
[INFO] Finished at: 2020-01-01T21:47:42+09:00
[INFO] ------------------------------------------------------------------------

C:\Data\mvn_download>dir
 ドライブ C のボリューム ラベルは Windows です
 ボリューム シリアル番号は F039-627E です

 C:\Data\mvn_download のディレクトリ

2020/01/01  21:47    <DIR>          .
2020/01/01  21:47    <DIR>          ..
2019/12/31  17:36           290,339 logback-classic-1.2.3.jar
2019/12/31  17:36           471,901 logback-core-1.2.3.jar
               2 個のファイル             762,240 バイト
               2 個のディレクトリ  184,503,398,400 バイトの空き領域

C:\Data\mvn_download>

また、以下のコマンドでlogback-core-1.2.3-sources.jarをダウンロードできます。

mvn dependency:get -DgroupId=ch.qos.logback -DartifactId=logback-core -Dversion=1.2.3 -Dclassifier=sources -Ddest=./

C:\Data\mvn_download>mvn dependency:get -DgroupId=ch.qos.logback -DartifactId=logback-core -Dversion=1.2.3 -Dclassifier=sources -Ddest=./
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:get (default-cli) @ standalone-pom ---
[INFO] Resolving ch.qos.logback:logback-core:jar:sources:1.2.3 with transitive dependencies
[WARNING] destination/dest parameter is deprecated: it will disappear in future version.
[INFO] Copying C:\DK\apache-maven-3.6.2\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3-sources.jar to C:\Data\mvn_download\.
[WARNING] Notice transitive dependencies won't be copied.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.960 s
[INFO] Finished at: 2020-01-01T21:49:29+09:00
[INFO] ------------------------------------------------------------------------

C:\Data\mvn_download>dir
 ドライブ C のボリューム ラベルは Windows です
 ボリューム シリアル番号は F039-627E です

 C:\Data\mvn_download のディレクトリ

2020/01/01  21:49    <DIR>          .
2020/01/01  21:49    <DIR>          ..
2019/12/31  17:36           290,339 logback-classic-1.2.3.jar
2020/01/01  21:31           399,141 logback-core-1.2.3-sources.jar
2019/12/31  17:36           471,901 logback-core-1.2.3.jar
               3 個のファイル           1,161,381 バイト
               2 個のディレクトリ  184,503,070,720 バイトの空き領域

C:\Data\mvn_download>

Apache Mavenをインストールしていれば、WindowsでもLinuxでも同じように使用できます。

参考

Apache Maven Dependency Plugin

以上

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?