UbuntuにMaven2リポジトリをWebDAVで構築する
Ubuntuには既にApacheが設定されている前提とします。
WebDAVの設定
2バイト文字対応
2バイト文字対応のため、mod-encoding をインストール
$ sudo apt-get install libapache2-mod-encoding
エンコーディング設定ファイルの作成
$ sudo vim encoding.conf ← 新規作成
<IfModule mod_encoding.c>
EncodingEngine on
NormalizeUsername on
SetServerEncoding UTF-8
DefaultClientEncoding JA-AUTO-SJIS-MS SJIS
AddClientEncoding "cadaver/" EUC-JP
</IfModule>
モジュールの有効化
$ sudo a2enmod dav $ sudo a2enmod dav_fs $ sudo a2enmod encoding
ディレクトリの作成
WebDAV用ディレクトリに書き込めるようにapacheユーザー権限に変更する。
$ sudo mkdir /var/www/maven2 $ chown -R www-data:www-data /var/www/maven2 $ sudo chmod 755 /var/www/maven2
パスワードファイルの作成
$ htpasswd -c /etc/apache2/passwd/.htpasswd-maven2 hoge
Location設定の追加
設定ファイルの
$ sudo vim /etc/apache2/sites-enabled/000-default
<Location /maven2>
Dav on
DavMinTimeout 600
AuthUserFile "/etc/apache2/passwd/.htpasswd-maven2
AuthName "Maven2 Server"
AuthType Basic
Require valid-user
</Location>
Apache再起動
$ /etc/init.d/apache2 restart
接続
下記URLにアクセスすると、Basic認証のボックスが表示されるので、先ほど作成したユーザ、パスワードを入力。
http://localhost/maven2
Maven設定
settings.xml
<?xml version="1.0" encoding="UTF-8"?>
<settings>
<servers>
<server>
<id>http-basic-repository</id>
<username>hoge</username>
<password>hoge</password>
</server>
</servers>
</settings>
pom.xml
pom.xmlにはdistributionManagementタグを追加します。
<distributionManagement>
<repository>
<uniqueVersion>false</uniqueVersion>
<id>http-basic-repository</id>
<name>Hoge repo</name>
<url>dav:http://server-domain/maven2</url>
</repository>
<snapshotRepository>
<uniqueVersion>true</uniqueVersion>
<id>http-basic-repository</id>
<name>Hoge repo snapshot</name>
<url>dav:http://server-domain/maven2/maven2-snapshot</url>
</snapshotRepository>
</distributionManagement>pom.xmlの設定でsnapshotRepositoryを設定していないと、下記のように怒られるので、ちゃんと設定しておきましょう。
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to configure plugin parameters for: org.apache.maven.plugins:maven-deploy-plugin:2.3
check that the following section of the pom.xml is present and correct:
<distributionManagement>
<!-- use the following if you're not using a snapshot version. -->
<repository>
<id>repo</id>
<name>Repository Name</name>
<url>scp://host/path/to/repo</url>
</repository>
<!-- use the following if you ARE using a snapshot version. -->
<snapshotRepository>
<id>repo</id>
<name>Repository Name</name>
<url>scp://host/path/to/repo</url>
</snapshotRepository>
</distributionManagement>
Cause: Class 'org.apache.maven.artifact.repository.ArtifactRepository' cannot be instantiated
デプロイ
>maven deploy