Apache Maven ã使ã£ã¦ã¿ãã(ãã® 1)
å½ããã°ã§ã¯ããã¾ã§ Apache Maven (以ä¸ãMaven) ã®è©±é¡ã¯æ¥µåé¿ãã¦ããããæ¨ä»ã®éçºäºæ ãéã¿ãã«ãææ© Maven ãªãã§ã¯éçºãã¾ã¾ãªããªãç¶æ³ã«ãªãã¤ã¤ãããSpring MVC ã§ã¯æ¨æºã®ãã«ããã¼ã«ã¨ãã¦æ¡ç¨ããããªã©ãMaven ã¯é¿ãã¦ã¯éããªããã®ã«ãªã£ã¦ããã
Maven ã¯ãªã便å©ãªã®ã ?
ãã«ãã©ã¤ããµã¤ã¯ã«ã®èªåå
IDE ã使ã£ã¦ããã¨ãã¾ããã³ã¨æ¥ãªãããç¥ããªãããããããã® Java ã®ã½ã¼ã¹ã³ã¼ããä¸ã¤ä¸ã¤æã§ã³ã³ãã¤ã«ããã®ã¯å¤§å¤ãªä½æ¥ã§ãããMaven ã§ããã¸ã§ã¯ãã管çãã¦ããã°ãã³ãã³ãä¸ã¤ã§ã³ã³ãã¤ã«ãå«ããã«ãã©ã¤ããµã¤ã¯ã«ãå ¨ã¦èªååã§ããã
ä¾åã©ã¤ãã©ãªã®ç®¡çãã§ãã
ããã¸ã§ã¯ããä¾åããã©ã¤ãã©ãªãä¸ã¤ä¸ã¤æ¢ãã¦ããã®ã¯å¤§å¤ãªä½æ¥ãããã Maven ãªããè¨å®ãã¡ã¤ã«ã§ãã pom.xml
ã«è¨è¿°ãã¦ããã° Maven ã®ãªãã¸ããªããåæã«ãã¦ã³ãã¼ããã¦ããããããã«ãä¾åããã©ã¤ãã©ãªãä¾åããå¥ã®ã©ã¤ãã©ãªãããã°ãã»ã¨ãã©ã®ã±ã¼ã¹ã§ããããåæã«ãã¦ã³ãã¼ããã¦ãããã
ãã©ã°ã¤ã³ã«ããæ¡å¼µæ§
Maven ã«ã¯æ§ã ãªãã©ã°ã¤ã³ããããããããçµã¿è¾¼ããã¨ã§ Maven ããã使ãããããã®ã«åºæ¥ããå ´åã«ãã£ã¦ã¯èªåã§ãã©ã°ã¤ã³ãä½ããã¨ãåºæ¥ãã
Scala ã Groovy ã O.K.
Maven ããããã°ãJava VM ä¸ã§åã Scala ã Groovy ã¨è¨ã£ãè¨èªã§ã®éçºãå¯è½ãããã Scala ã Groovy ãå¥éã¤ã³ã¹ãã¼ã«ããå¿ è¦ããªãã
ãããã£ãçç±ã«ãããMaven ã®ä½¿ãæ¹ãè¦ãããã¨ã¯é常ã«æå¹ã§ãããéçºã®æéã大ãã«çããã¨ãå¯è½ã«ãªããããã§ä»åãã㯠Maven ã®åºæ¬çãªä½¿ãæ¹ãé£è¼ãã¦ãããã¨æãã
Maven ã使ã
æºå
Java Development Kit (JDK) ãã¤ã³ã¹ãã¼ã«ããã¦ãããã¨ãå¿ é ã§ããã
以ä¸ã®ãµã¤ããã Maven ããã¦ã³ãã¼ãããã
Maven – Welcome to Apache Maven
ãããé©å½ãªãã©ã«ãã«è§£åããç°å¢å¤æ°ã®è¨å®ãè¡ãã
ç°å¢å¤æ° MAVEN_HOME
ã«ã¯ Maven ã解åãããã©ã«ããæå®ããããã¤ã¦ã¯ M2_HOME
ã«æå®ãããã¨ã«ãªã£ã¦ããããç¾å¨ã¯ Eclipse åããã©ã°ã¤ã³ã§ãã Maven EnIDE ã®é¢ä¿ã§ MAVEN_HOME
ã«è¨å®ããæ¹ãè¯ãã
ç°å¢å¤æ° PATH
ã«ä»¥ä¸ã追å ããã
;%MAVEN_HOME%\bin
以ä¸ã®è¨å®ãæ¸ãã ãã³ãã³ãããã³ãããç«ã¡ä¸ã㦠mvn -version
ã¨å
¥åã㦠Enter ãæ¼ãã¦ã¿ããã
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T20:57:37+09:00)
Maven home: C:\Maven\bin\..
Java version: 1.8.0_51, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.8.0_51\jre
Default locale: ja_JP, platform encoding: MS932
OS name: "windows 7", version: "6.1", arch: "amd64", family: "dos"
ã®ããã« Maven ã®ãã¼ã¸ã§ã³ã Java ã®ãã¼ã¸ã§ã³ãªã©ã®æ å ±ãåºã¦ããã°ãMaven ã¯æ£ããã¤ã³ã¹ãã¼ã«ããã¦ããã
ããã¸ã§ã¯ããä½ã
ã³ãã³ãããã³ããã§
mvn archetype:generate -DarchetypeArtifactId=maven-archetype-quickstart -DgroupId=jp.mydns.akanekodou -DartifactId=MavenSample
ã¨å ¥åã㦠Enter ãæ¼ããä¸è¡ã§æã¡è¾¼ãã®ã§å°ãé¢åããç¥ããªãã
éä¸ã§ä½åº¦ãããã³ãããåºãããåã« Enter ãæ¼ãã¦é²ãã¦è¯ãã
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 33.270 s
[INFO] Finished at: 2015-08-07T10:33:16+09:00
[INFO] Final Memory: 15M/167M
[INFO] ------------------------------------------------------------------------
ã¨ã¡ãã»ã¼ã¸ãåºã¦ããã°ããã¸ã§ã¯ãä½æå®äºã ãç´ä¸ã« MavenSample
ã¨ãããã£ã¬ã¯ããªãåºæ¥ã¦ããã¯ãã ã
Eclipse ã«åãè¾¼ã
Java åãã® IDE ã¯ããããããããä»å㯠Eclipse ã«ã¤ãã¦è§£èª¬ããã
ã¾ã㯠Eclipse ã«ãMaven ç¨ã®ãã©ã°ã¤ã³ã§ãã m2e ãã¤ã³ã¹ãã¼ã«ããå¿ è¦ããããããã®æé ã«ã¤ãã¦ã¯å²æããã
Package Explorer ã§å³ã¯ãªãã¯ã㦠[Import...] ãé¸ã¼ãã
[Existing Maven Projects] ãé¸æã㦠[Next] ãæ¼ãã
[Root Directory] ã«å ã»ã©ä½æ¥ãããã©ã«ãåãå ¥ããã¨â¦
å ã»ã©ä½ã£ãããã¸ã§ã¯ãã«ãã§ãã¯ãã¼ã¯ãå ¥ã£ã¦ããããã®ã¾ã¾ [Finish] ãæ¼ãã
ãã§ããããã¸ã§ã¯ããåãè¾¼ãããããä½ããè¦åãåºã¦ãã¾ããã
ãJ2SE-1.5 ã® JRE ããªãã !ãã¨ããè¦åã§ããããããããã (è¦ç¬)ã
pom.xml
ã®ä¿®æ£
ãã®è¦åãæ¶ãã«ã¯ pom.xml
ãä¿®æ£ããå¿
è¦ããããã¾ãå
ã® pom.xml
ããããªæãã
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>jp.mydns.akanekodou</groupId> <artifactId>MavenSample</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>MavenSample</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project>
ããã次ã®ããã«ä¿®æ£ããã
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>jp.mydns.akanekodou</groupId> <artifactId>MavenSample</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>MavenSample</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> </dependencies> </project>
ä¿®æ£å 容ã¨ãã¦ã¯
- ããããã£å¤ã®è¨å®(æåã¨ã³ã³ã¼ã㯠UTF-8 ã«ãJava ã®ãã¼ã¸ã§ã³ã 1.8 ã«)
- JUnit ã®ãã¼ã¸ã§ã³ãææ°ã® 4.12 ã«
ã¨ãã£ãã¨ããããã®å
容ã§ä¿åããã¨ç¨ãªããã¦ã¨ã©ã¼ãåºãããããã¯ãpom.xml
ã®å
容ãåæ ããã¦ãªãã !ãã¨ãããã¨ãªã®ã§ãææ°ã®å
容ãåæ ãããã°ããã
Alt + F5 ãæ¼ãã¨ãã®ãããªç»é¢ãåºã¦ããã®ã§ãMavenSampleãã«ãã§ãã¯ãå ¥ã㦠[OK] ãæ¼ãã
æ´æ°ãããããã¸ã§ã¯ãã¯ãã®ããã«ãªã£ã¦ããã¯ããã¨ã©ã¼ãæ¶ã㦠J2SE-1.5 ãã JavaSE-1.8 ã«ãä¾åã©ã¤ãã©ãªã junit-4.12.jar
㨠hamcrest-core-1.3.jar
ã«å¤ãã£ã¦ããã
ããã§ä¸æè°ãªã®ããä¾åããã©ã¤ãã©ãªã¨ãã¦ã¯ junit-4.12
ããæå®ãã¦ããªãã®ã«åæã« hamcrest-core-1.3
ã追å ããã¦ãããã¨ããã㯠JUnit 4 ãå
é¨çã« hamcrest-core
ã使ããã¨ã Maven ãªãã¸ããªã«æ¸ããã¦ãã¦ãä¾åã©ã¤ãã©ãªã¨ãã¦èªåã§å¼ã£å¼µã£ã¦ãã¦ããã¦ããã®ã ã