Maven2ã®pom.xmlã®æ§æ
ä»äºã§Hudsonãå°å
¥ãããã¨æã£ã¦ããã®ã§ãããMeven2ã¨çµã¿åãããæ¹ãããããã§ãããããã®ã§ãMaven2ã«ã¤ãã¦èª¿ã¹ã¦ã¿ã¾ããã
åæ¥ãããããã£ãå¾ã§ã®Maven2ã®å°è±¡
- ãã¾ã©ãã³ãã³ãã©ã¤ã³ãã¼ã¹
- Eclipseã¨ãããªã«ç¸æ§ãè¯ããªã(Eclipseã®ãã©ã°ã¤ã³ãå¾®å¦)
- Antã¨æ¯ã¹ã¦æåãè¦ããªã
- XMLã®è¨è¿°éãå¤ã
- ç¨èªãå¤ã
- æåã®å£ãè¶ããã¨æå¤ã¨ç°¡å
- ç¶ç¶çã¤ã³ãã°ã¬ã¼ã·ã§ã³ãããå ´åãAntãã楽ããã«æãã
- å«ã§ãéçºããã»ã¹ã確ç«ããã
Mavenã¯1ã®é ã«ããã£ã¦ã¿ã¦ãAntã«éã帰ã£ãæãåºãããã®ã§ãããããæªãå°è±¡ãå¤ãã®ã§ãããããã¯ææ
¢ãã¦Hudsonã使ã£ãéç¨ã確ç«ãããããã«é å¼µã£ã¦ã¿ã¾ãã
pom.xml
ã¾ããã®xmlãåé¡ãªããã§ãã
Mavenãµã¤ãã«全体の構成ãè¼ã£ã¦ãã¾ãããã¾ãããã§ä½¿ãã®ãæ¢ããããªãããã§ãã
ãããã©ããªå«ãããã ããã¨ã
ã¨ãæã£ã¦ããã®ã§ãããåç´ãªæ§æã ã¨å®ã¯ãããªã«ä½¿ãé
ç®ãå¤ããªãã£ãããã¾ãã
pom.xmlã®æ§æ(ãã使ããã®ã ã)
<?xml version="1.0" encoding="UTF-8"?> <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"> <!-- ããã¸ã§ã¯ãè¨å® --> <build> <!-- å ¥åºåã®è¨å® --> <plugins> <plugin> <!-- ãã«ãè¨å® --> </plugin> </plugins> </build> <reporting> <plugin> <!-- ã¬ãã¼ãè¨å® --> </plugin> </reporting> <dependencies> <dependency> <!-- ã©ã¤ãã©ãªä¾åé¢ä¿ã®è¨å® --> </dependency> </dependencies> </project>
ã³ã¡ã³ãã§æ¸ãããã¨ããã«ã¯ãããããã®åè¦ç´ ãå ¥ãã®ã§ããã®ã¾ã¾å®è¡ã§ããããã§ã¯ãªãã®ã§ãããããè¦ãã¨ãããªã«é ç®ãå¤ããªããã¨ããããã¨æãã¾ãã
以ä¸ã1ã¤ãã¤è¿½ã£ã¦ããã¾ãã
ããã¸ã§ã¯ãè¨å®
<groupId>jp.tanamon</groupId> <artifactId>mvntest</artifactId> <packaging>war</packaging> <version>1.0.0</version> <name>${project.artifactId}</name> <url>http://tanamon.jp/${project.artifactId}/</url>
groupId
çµç¹ã¨ãã¦ã¦ãã¼ã¯ã§ããã°ããã®ã§ãJavaã®ããã±ã¼ã¸åã¨åãã«ãã¦ããã¨ããããããã§ãã
artifactId
ãããã¯ããã¨ã«ã¦ãã¼ã¯ã§ããã°ããã®ã§ãEclipseã®ããã¸ã§ã¯ãåãããã¨åãã«ãã¦ããã¨ããããããã§ãã
version
ããã°ã©ã ã®å¤æ´ãã¨ã«ã¦ãã¼ã¯ã«ãªããã®ã ã¨æãã¾ãããã³ããªã³ã°ã«ã¼ã«ã¯ç¤¾å
ã§ã«ã¼ã«æ±ºããããã°ããã§ããããããå®éã®éçºã§ã¯ããã«æ¸ããã¦ããã¨ç®¡çãä¸ä¾¿ãªæ°ãããã®ã§ãããã©ã解決ãã¹ããã¯ãã®ãã¡èª¿ã¹ã¾ãã
name
ã¬ãã¼ãçã«åºã表示å称ã§ããartifactIdãapp0001ã¿ãããªååã«ããªãããããªããããªä¸æè°ãªçµç¹ããã¾ã«ããã®ã§ããããã£ãå ´åã«è¡¨ç¤ºåãå¥éæå®ã§ãã¾ããä¾ã§ã¯å¤æ°ã使ã£ã¦artifactIdã¨åãã«ãã¦ãã¾ãããæ®éã¯ããã§ããããã«æãã¾ãã
url
ãµã¤ãã®URLã§ããå
¥å£ãè¤æ°ããå ´åã¯ã©ããããã§ãããããï¼
å ¥åºåè¨å®
<finalName>${project.artifactId}-${project.version}</finalName> <sourceDirectory>src/main/java</sourceDirectory> <outputDirectory>target/classes</outputDirectory> <testSourceDirectory>src/test/java</testSourceDirectory> <testOutputDirectory>target/test-classes</testOutputDirectory> <resources> <resource> <directory>src/main/resources</directory> </resource> </resources> <testResources> <testResource> <directory>src/test/resources</directory> </testResource> </testResources>
ãããã®è¨å®å¤ã¯ããã©ã«ãå¤ã§ããMaven2æ¨å¥¨ã®æ§æãããã§ãããç¹ã«ãã£ã¬ã¯ããªæ§æãªã©ããã®æ§æã ã¨ã©ãå¬ããã®ããã®ãã¡èª¿ã¹ã¾ãã
ã¾ããæåã¯å¾ã£ã¦ããã»ããä½è¨ãªç¾è±¡ã«æ©ã¾ãããªãã¦ããã¨æãã¾ãã
ãã«ãè¨å®
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin>
Maven2ã¯å¤§æµã®æ©è½ããã©ã°ã¤ã³ã«ãã£ã¦å®è£
ããã¦ãããããã»ã¨ãã©ã®å ´åãMaven2ã®æ©è½ã使ãã¨ãããã¨ã¯ãã©ã°ã¤ã³ã追å ãããã¨ãããã¨ã«ãªãã¾ãã
ã¾ãããã«ãè¨å®ã¨ã¬ãã¼ãè¨å®(å¾è¿°)ã¯å¯¾ã«ãªã£ã¦ãããã®ãå¤ãã§ãã
ããã§ã¯ãã«ãæã«ä½¿ç¨ãããã©ã°ã¤ã³ãæå®ãã¾ãã
ãã使ããããã©ã°ã¤ã³ã¯Available Pluginsã«ä¸è¦§ãããã¾ãã
åãã©ã°ã¤ã³ãã¼ã¸ã®Usageã®hereãªã³ã¯ã®å
ã«ã使ãæ¹ãè¼ã£ã¦ãã¾ãã
è±èªã§ãããåããã³ãã¬ã¼ãã§æ¸ããã¦ããã®ã§ãä½ã¨ãèªããã¨æãã¾ãã
ã¡ãªã¿ã«ãä¸è¨ä¾ã¯Compiler Pluginã®è¨å®ã«ãªãã¾ããJDKã®ãã¼ã¸ã§ã³ãæå®ã§ãããã®ãªã®ã§ã大æµã®éçºã§ä½¿ããã©ã°ã¤ã³ã ã¨æãã¾ãã
ã¬ãã¼ãè¨å®
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <configuration> <docencoding>UTF-8</docencoding> <charset>UTF-8</charset> <encoding>MS932</encoding> <bottom></bottom> </configuration> </plugin>
ãã¡ãã®è¨å®ããã©ã°ã¤ã³ã«ãã£ã¦ç°ãªãã¾ãããè¨è¿°ã¯å¤§ä½ä¸ç·ã§ããããã§ã¯ãã¬ãã¼ãä½ææã«ä½¿ç¨ãããã©ã°ã¤ã³ãæå®ãã¾ãã
ä¸è¨ä¾ã¯ãJavadoc Pluginã®è¨å®ã«ãªãã¾ãã
ã¾ããã¦ãã®ä¼ç¤¾ã§ã¯æ®å¿µãªãã¨ã«Javaã½ã¼ã¹ãUTF-8åããã¦ããªãã®ã§ãæåã³ã¼ããMS932ã«ãã¦ãã¾ãã
ã©ã¤ãã©ãªä¾åé¢ä¿ã®è¨å®
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency>
ã©ã¤ãã©ãªã®ä¾åé¢ä¿ãæ示çã«æå®ã§ãã¾ãã
ããã«è¨è¿°ãããã¨ã§ããã¨ãã°UnitTestæã«ãã使ç¨ããªããããªã©ã¤ãã©ãªãé¤ããããããã¨ãã§ãã¾ãã
ã¨ã¯ãããã©ã¤ãã©ãªãã¨ã«groupIdã¨artifactIdãéããããMaven Repositoryããå®ç¾©ãæ¢ãã¦ãã¾ãã
ä¸è¨ä¾ã§ã¯junit 3.8.1ã®POM Dependencyã®è¨è¿°ãããã³ãã¬ã¼ããæ¢ãã¾ãã
version
versionã¯è¨è¿°ããªãã¨ãèªåçã«ææ°çãåå¾ãã¦ãã¾ããã¾ããç¯å²æå®ããããã¨ã§ãã¤ãã¼ãã¼ã¸ã§ã³ã¢ããã®ç¯å²ã§ãã¼ã¸ã§ã³ã¢ãããããã¨ããæå®ãã§ãã¾ãã
ããæ®éã®éçºã§ã¯ä½¿ããªãæ°ããã¾ãã
ãã¹ãå¾ã«åæã«ãã¼ã¸ã§ã³ã¢ããããããæ²æ¨ã§ãã
åºæ¬ã¯æ示çã«ãã¼ã¸ã§ã³æå®ãè¡ã£ã¦ãããã®ã ã¨æãã¾ãã
scope
ãã®å¤ã§ã©ã®ã¹ã³ã¼ãã§ã©ã¤ãã©ãªãå¿ è¦ããæå®ãã¾ãã
- compile 常ã«ã¯ã©ã¹ãã¹ã«è¿½å ããé å¸ç©ã«å«ãããããã©ã«ãå¤ã
- provided ã³ã³ãã¤ã«æã«å¿ è¦ãªå ´åãé å¸ç©ã«ã¯å«ããªããServlet APIãªã©ã
- runtime ã³ã³ãã¤ã«æã«ä¸è¦ã§ãå®è¡æã«å¿ è¦ãªå ´åãé å¸ç©ã«ã¯å«ããªããJDBCãã©ã¤ããªã©ã
- test ãã¹ãå®è¡æã«ã¯ã©ã¹ãã¹ã«è¿½å ãããJUnitãªã©ã
- system ã¹ã³ã¼ãã¨ãã¦ã¯compileã¨åä¸ããã¼ã«ã«ã®å¥ã®å ´æã«ããã©ã¤ãã©ãªãsystemPathã¿ã°ã§æ示çã«æå®ããã
- import Maven2.0.9以éã®æ°æ©è½ãdependencyManagementã使ã£ã¦ãã«ããã«ãããããããçç¥ã
ããã辺ã¯èªèº«ããªãã®ã§ééã£ã¦ãããããããªãã®ã§ã詳ããã¯Dependency Scopeãåç
§ã®ãã¨ã
Maven Repositoryã§è¦ã¤ãããªãã©ã¤ãã©ãª
DjUnitçã®ã©ã¤ãã©ãªã®ããã«ãMaven Repositoryã«ç¡ãã©ã¤ãã©ãªã«ã¤ãã¦ã¯ã以ä¸ã®ã©ã¡ããã®å¯¾å¿ããã¾ãã
ãã¼ã«ã«ãªãã¸ããªã«å ¥ãã
mvnã³ãã³ãã§ã©ã¤ãã©ãªãæ示çã«ç»é²ããã¾ãã
mvn install:install-file -Dfile=${JARãã¡ã¤ã«ã®ãã¹} -DgroupId=${groupId} -DartifactId=${artifactId} -Dversion=0.8.3 -Dpackaging=jar -DgeneratePom=true
artifactIdã¨groupIdã®å¤ã¯pom.xmlã¨ä¸è´ãããã°ããã®ã§ä½ã§ãããã§ãããå½åè¦åã¯åãããæ¹ãããã¨æãã¾ãã
ã¡ãªã¿ã«ãDjUnitãç»é²ããæã¯ãããªã³ãã³ãã§ç»é²ãã¾ããã
mvn install:install-file \ -Dfile=C:\apache-maven-2.0.9\install-lib\djunit.jar \ -DgroupId=jp.co.dgic \ -DartifactId=djunit \ -Dversion=0.8.3 \ -Dpackaging=jar \ -DgeneratePom=true
社å ç¨ãªãã¸ããªãä½ã
ãã¼ã«ã«ãªãã¸ããªã®å ´åãããã°ã©ãã®ç°å¢ãã¨ã«è¨å®ãã¦ãããå¿
è¦ããããããè¤æ°äººã§éçºããã¦ããã¨ç ´ç¶»ãã¾ãã
ãã®å ´åã社å
ç¨ãªãã¸ããªãä½ããã¨ã§ä¸å
管çãã§ãã¾ãã
社å
ãªãã¸ããªã®ä½æã¯ã¡ãã£ã¨å¤§å¤ãããªã®ã§ããã®ãã¡ããã¾ãã
æå¾ã«
ã¨ã©ã¼ãçºçããå ´å
mvnã³ãã³ãã«-Xãªãã·ã§ã³ãä»ãã¦å®è¡ããã¨ãããã°ã¢ã¼ãã«ãªãã®ã§ããããããããã¾ããã