LoginSignup
13

More than 5 years have passed since last update.

mavenプロジェクトでjarを追加する

Posted at

Mavenプロジェクトでダウンロードしてきたjarをインストールする方法をメモです。

refs: http://wiki.fdiary.net/maven2/?CookBook#l11 - サードパーティのJarをインストールする

対象

mavenで依存関係が定義されているプロジェクト
NetBeansの場合、「依存性」フォルダがあり、「ライブラリ」フォルダないもの

方法

  1. jarをmavenのローカルリポジトリにインストールします。 Windowsのgit bashの場合は以下の通りです。 fileには絶対パスを指定します。 groupId/artifactId/versionは任意ですが、jarの名前に合わせておきます。
mvn install:install-file -Dfile=/C/foo/guava-18.0.jar -DgroupId=com.google.guava -DartifactId=guava \
-Dversion=18.0 -Dpackaging=jar -DgeneratePom=true
  1. プロジェクトのpom.xmlにリポジトリを指定します。 プロジェクトの直下あるpom.xmlのdependenciesの中に、以下のように追加します。
<dependency>
  <groupId>com.google.guava</groupId>
  <artifactId>guava</artifactId>
  <version>18.0</version>
</dependency>

これでプロジェクト内でjarのクラスを参照できるようになります。

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
13