~/.m2/settings.xml"
に以下の記述を書いておきます。
<settings> <proxies> <proxy> <active>true</active> <protocol>http</protocol> <host>hogehoge.jp</host> <port>81</port> <username>fuga</username> <password>fuga</password> <nonProxyHosts>www.google.com|*.hoge.jp</nonProxyHosts> </proxy> </proxies> </settings>
mvn archetype:create -DgroupId=nu.mine.kino.mavensample -DartifactId=kino-app
グループIDとプラグインIDを指定するんですね。
mvn eclipse:eclipse
これでEclipse関連のファイルができあがります。以後、Eclipse上で管理できるわけですね。
出力されるファイル内で
M2_REPO
という変数を使用しているので、Eclipseの変数としてM2_REPOを定義しておきます。値はローカルリポジトリへのパスを指定しておきます。
通常pom.xmlはデフォルト値は省略されますが、それを省略しないで出力します。
mvn projecthelp:effective-pom
コンソールに
<?xml version="1.0"?><project> <modelVersion>4.0.0</modelVersion> <groupId>nu.mine.kino.mavensample</groupId> <artifactId>kino-app</artifactId> <name>kino-app</name> <version>1.0-SNAPSHOT</version> <url>http://maven.apache.org</url> <build> <sourceDirectory>t:\workspace3.2\kino-app\src\main\java</sourceDirectory> <scriptSourceDirectory>src/main/scripts</scriptSourceDirectory> <testSourceDirectory>t:\workspace3.2\kino-app\src\test\java</testSourceDirectory> <outputDirectory>t:\workspace3.2\kino-app\target\classes</outputDirectory> <testOutputDirectory>t:\workspace3.2\kino-app\target\test-classes</testOutputDirectory> <resources> <resource> <directory>t:\workspace3.2\kino-app\src\main\resources</directory> </resource> </resources> <testResources> <testResource> <directory>t:\workspace3.2\kino-app\src\test\resources</directory> </testResource> </testResources> <directory>t:\workspace3.2\kino-app\target</directory> <finalName>kino-app-1.0-SNAPSHOT</finalName> <plugins> <plugin> <artifactId>maven-projecthelp-plugin</artifactId> <version>2.0-beta-1</version> </plugin> </plugins> </build> <repositories> <repository> <snapshots> <enabled>false</enabled> </snapshots> <id>central</id> <name>Maven Repository Switchboard</name> <url>http://repo1.maven.org/maven2</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <releases> <updatePolicy>never</updatePolicy> </releases> <snapshots> <enabled>false</enabled> </snapshots> <id>central</id> <name>Maven Plugin Repository</name> <url>http://repo1.maven.org/maven2</url> </pluginRepository> </pluginRepositories> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> <reporting> <outputDirectory>target/site</outputDirectory> </reporting> </project>
が出力されました。ファイルにリダイレクトして、ちょこちょこ編集して使うことができて便利です。デフォルト値がでてるのがよいですね。
Mavenは必要なライブラリがローカルにあるかを探し、なかったらネット上のリポジトリを探しに行きます。で必要なライブラリですが、pom.xmlで以下のように指定します。
<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> dependencies内に複数かける </dependencies>
<groupId /> <artifactId /> <version />
は必須みたいですね。
mvn package
でjarが作成されます。
mvn install
で該当プロジェクトがローカルリポジトリ(~/.m2のことです)にインストールされます。複数のプロジェクトが依存しあってる構成で開発するときはローカルリポジトリに自分のライブラリをインストールすることで、再帰的(?)に開発すればよいのかな?つまり
ProjectA ProjectB <- ProjectAに依存してる
場合、まずProjectAをinstallして、んでProjectBはpom.xmlでProjectAに依存してる、と書いておく、と。
ちなみにインストールしたときのディレクトリ構成ですが
groupId(の.を/で切ったモノ)/artifactId
となるのでgroupIdは適度な長さにしておいた方が良さそうです。EclipseのプラグインIDだと失敗するな(´д`;)↑もうやっちゃった(´д`;)
この記事は
現在のアクセス:65844