m2eclipseã§mavenããã¸ã§ã¯ããã¤ãã£ã¦ã¿ã
m2eclipseã®ã¤ã³ã¹ãã¼ã«
ä½æ
m2eclipseãã¯æ·±ãèãã¦ããªããåã«ããããã£ã¦ããããã®ã§ã
Eclipseã®Help>Install New Softwareã«http://m2eclipse.sonatype.org/sites/m2e ã追å ãã¦ã¤ã³ã¹ãã¼ã«ããã ãã
æ©éããã¸ã§ã¯ããã¤ãã£ã¦ã¿ã
File>New>Maven
ããMaven Projectãé¸ãã§Nextã
ãã§ãã¯ã¢ã¦ãã¨ãã¢ã¸ã¥ã¼ã«ããã¨ã§ãã£ã¦ã¿ããã
archetypeã£ã¦ã®ãããããã¹ããããã¨ããããã³ãã¬ã¼ãã¨ããããªé°å²æ°ã ã
ã¨ããããã¯ã¾ãã¾ã§ã¤ãã£ã¦ã¿ããã¨ã«ãããã®ã§
Create a simple projectã«ãã§ãã¯ãã¨ãã
Nextããã¨ãªããGroup Idã¨ãArtifact Idããããã¨ããããã
ã°ã«ã¼ã Idï¼groupIdï¼ã¯ããã¸ã§ã¯ããä¸æã«èå¥ããååã§ãããã¸ã§ã¯ãã®ã«ã¼ãããã±ã¼ã¸åãæå®ããã®ãä¸è¬çã§ãã
ã¢ã¼ãã£ãã¡ã¯ã Idï¼artifactIdï¼ã¯ããã¸ã§ã¯ãã®ææç©ã®ååã§ããJARãWARã«ã¤ããååãæå®ãã¦ãã ããã
http://d.hatena.ne.jp/Kishi/20090228/1235813480
ã£ã¦ãã£ããã ãã©http://maven.ozacc.com/ã¿ãã¨ãªããé©å½ãããã
ã¨ããããgroup idãmaven-testãartifact idã¯maven-sample01ã¨ãã«ãã¦packageã¯jarã«ãã¦ã¿ãã
ãªãã空ç½ãããã©ã¾ããããã£ã¦Finishããã¨ãªããmavenããã«ããã«ãåãã¦ããã¸ã§ã¯ããã§ããã
ãããã§ããã
ä¾åæ§ã追å ãã¦ã¿ã
ããã¸ã§ã¯ãã®ã³ã³ããã¹ãã¡ãã¥ã¼ããMaven>Add Dependency
ãªããcommons-langã¨ãããã¦ã¿ãã¨åè£ãåºã¦ã»ã»ã»ããªãã£ãã
Repositoryã®IndexãUpdateããªãããªãã ããªãã失æããã
ãã©ã¼ã©ã ã¿ã¦ããæ¥ã«ãã£ã¦çºçã¨ãæ¸ãã¦ãã£ãï½ã®ã§
ã¨ããããã¯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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>maven-test</groupId> <artifactId>maven-sample01</artifactId> <version>0.0.1-SNAPSHOT</version> <dependencies> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>2.5</version> </dependency> </dependencies> </project>
ããã¨ã¾ãmavenããªãããã«ããã«ããã¦ãcommons-langã使ããããã«ãªã£ã¦ããï¼ï¼
package maventest; import org.apache.commons.lang.StringUtils; public class Sample01 { private static final String PREFIX = "hoge_"; public static void main(String[] args) { System.out.println(new Sample01().addPrefix("test")); } public String addPrefix(String str) { if(StringUtils.isBlank(str)) return PREFIX; return PREFIX + str; } }
ã¡ããã¨ã³ã³ãã¤ã«éãã
ãã¹ããã¤ãã¦ã¿ãããä»åº¦ã¯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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>maven-test</groupId> <artifactId>maven-sample01</artifactId> <version>0.0.1-SNAPSHOT</version> <dependencies> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>2.5</version> <scope>compile</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.3</version> <scope>test</scope> </dependency> </dependencies> </project>
junitã®dependencyã追å ãããã ãã©ãä»åº¦ã¯scopeãæå®ãã¦ã¿ããtestã ã¨ãã¹ãã®ã¨ãããä¾åæ§ãã§ããªãã
package maventest; import static org.junit.Assert.*; import org.junit.Test; public class Sample01Test { @Test public void testAddPrefix() { String prefix = "hoge_"; String input = "maventest"; assertEquals(prefix + input, new Sample01().addPrefix(input)); } }
æ®éã«JUnitåããããããªãã¦ãmavenã®testãå®è¡ãã¦ã¿ãã
Run AsããMavenå®è¡ãã¦ãgoalãtestã«ãã¦ã¿ãã
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
ãããåãã¦ãã£ã½ããã
ä»åº¦ã¯ããã¨å¤±æãã¦ã¿ãã
@Test public void testAddPrefix() { String prefix = "baka_"; String input = "maventest"; assertEquals(prefix + input, new Sample01().addPrefix(input)); }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
ãããããã¡ããã¨å¤±æããã