基本概念 †プロジェクトで必要となるタスクをMavenが定義する各フェーズ(プロジェクト作成、コンパイル、テスト、ドキュメント、パッケージング)で実施できるようにしている。 各フェーズはmavenプラグインで実装されており、初回実行時にダウンロードするためネットワーク接続が必要。
java -cp 'target/dependency/*.jar' hogehoge 構成 †親pom.xmlのDependencyManagementセクションにて、各サブモジュールで使う可能性があるものを列挙しておく。 pomが競合したとき †複数の親pomが混在する場合は、一番近い依存性定義が優先される。 以下のプロジェクトではD1.0が利用される。
jarの中に依存ライブラリ †maven-shade-plugin インストール †Javaとmvnへのパスが通っていればよし。Eclipseならm2e(昔のm2eclipse)が標準。J2EEパックなら標準インストール済み。m2eを使うときにはm2eプロファイルが自動的に読まれる。 MavenのバージョンとJDKのバージョン対応表 †
プロジェクトの生成 †
mvn archetype:generate Webプロジェクトのときの依存性 †
<dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency>
<dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.glassfish.web</groupId> <artifactId>jstl-impl</artifactId> <version>1.2</version> <exclusions> <exclusion> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> </exclusion> <exclusion> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> </exclusion> <exclusion> <groupId>javax.servlet.jsp.jstl</groupId> <artifactId>jstl-api</artifactId> </exclusion> </exclusions> </dependency> pom.xmlの記載 †基本情報 †変数の定義と利用 †<properties> <arbitrary.property.a>This is some text</arbitrary.property.a> <hibernate.version>3.3.0.ga</hibernate.version> </properties> ... <dependencies> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate</artifactId> <version>${hibernate.version}</version>
profileの指定 †mvn help:active-profilesで現状有効なprofileを見ることができる。 <profile> <id>profile-A</id> <properties> <value>AAA</value> </properties> </profile> <profile> <id>profile-B</id> <properties> <value>BBB</value> </properties> </profile> リポジトリ情報 †
$ mvn dependency:go-offline 3種類定義する。
三種類なので一か所だけ変更しても、残りは変更されておらずはまったので注意。 依存関係jar表示 †mvn dependency:tree
リポジトリごとのTimeout †
リポジトリポリシー †
ローカルリポジトリ †デフォルトはユーザーの.m2だが、settings.xmlで設定可能 <localRepository>/path/to/local/repo</localRepository> Eclipse上での操作 †既存プロジェクトをmavenプロジェクトに変更 †右クリックして構成→convert to maven project 新規作成 †右クリックして新規作成→Maven→Maven Project プラグイン †maven-release-plugin †pomのバージョンアップやタグの設定を自動でやってくれるプラグイン http://www.nulab.co.jp/kousei/chapter6/05.html
プラグインリポジトリは以下に設定する。 http://repo1.maven.org/maven2/ 注意点など †特別な設定をしない限り、jarファイルをネット経由で持ってくるので接続が必要。 主要操作など †プロジェクト作成 †
mvn archetype:create -DgroupId=com.rutake.sample -DartifactId=app -Dversion=0.0.1
mvn archetype:generate -DgroupId=com.rutake.sample -DartifactId=webapp -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
<dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.3</version> <scope>provided</scope> </dependency> コンパイル †
mvn compile バージョンの指定はプロパティで行う。 maven.compiler.source, maven.compiler.target テスト †
mvn test
mvn test -Dtest={テストクラス名} パッケージ作成 †mvn package リリース †
どのコマンドも初回実行時には関連jarをごっそりダウンロードするので時間はかかる。二回目以降は早い。 リモートリポジトリに配備 †
mvn deploy
mvn deploy:deploy-file -Durl=<アップロード先URL> -DrepositoryId=<リポジトリのID> -Dfile=<Jarファイルへのパス> -DgroupId=<グループID> -DartifactId=<アーティファクトID> -Dversion=<バージョン> -Dpackaging=jar
mvn deploy:deploy-file -Dfile=<POMFILE> -Durl=<リポジトリURL> -DrepositoryId=<リポジトリのID> -DgroupId=<グループID> -DartifactId=<アーティファクトID> -Dversion=<バージョン> -Dpackaging=pom -DgeneratePom=false
curl -u juven-test:****** https://oss.sonatype.org/service/local/staging/deploy/maven2/com/ juvenxu/ossrh-test/1.1/ossrh-test-1.1.pom --request PUT --data @pom.xml eclipseプロジェクト作成 †mvn eclipse:eclipse どのprofile,pom,settingsが有効なのか出力 †mvn help:active-profiles mvn help:effective-pom mvn help:effective-settings settings.xmlは~/.m2におかないと自動では読み込んではくれないので注意。 リポジトリのタイムアウト設定 †http://d.hatena.ne.jp/Kazuhira/20130623/1371978072 文字列置換 †フィルタリングという。以下のURLを参照せよ http://www.limy.org/program/java/maven/filtering.html TIPS †
トラブルシューティング †
artifact-versionno.pom.lastUpdated リポジトリの検索 †リポジトリソフトウェアの比較 †
http://binary-repositories-comparison.github.io/ 用語など †
リポジトリソフト †Archiva,sonatype nexus,Artifactoryがある。比較表がある。 http://docs.codehaus.org/display/MAVENUSER/Maven+Repository+Manager+Feature+Matrix nexus(sonatype nexus) †nexus インストール手順 †warバンドルがなくなってしまった。nexusディレクトリ以下をTOMCAT_HOME/webappsに突っ込んだが、NoClassDefFoundErrorが出たので、上位のlibディレクトリのjarをnexus/WEB-INF/libにつっこんで起動したところ無事成功。ユーザーディレクトリにsonatype-workディレクトリを作るので注意。またコンパイルバージョンがかなり最新のものを使っているのでJDK6の場合は2.5までしか使えない。 環境変数PLEXUS_NEXUS_WORKでワークディレクトリの設定をする 設定ファイル †PLEXUS_NEXUS_WORK/confにある。
nexusバージョンアップ †本体だけでOK。 リポジトリの設定 †Proxy,3rdParty,Hosted,Virtualの種類がある。 一般公開されているリポジトリのProxyとして使うならProxyだが、初期状態で設定されているので特に追加は不要だろう。「Download Remote Indexes」の設定をTrueにしておくとNexusの動いているマシンにダウンロードしておいてくれる。OracleのODBCドライバのような一般公開リポジトリに存在しない場合は3rdParyリポジトリに手動でアップロードする。自作のアプリのアップロード場所はHostedにする。 モジュールの考え方 †http://blog.livedoor.jp/android1009/archives/24341372.html トラブルシューティング †Could not find the main class: org.codehaus.plexus.classworlds.launcher.Launcher. M2_HOMEを正しく設定しないと出てしまう。
Counter: 12459,
today: 5,
yesterday: 2
|