본문 바로가기

OLD/Languages

[Maven] Maven 간단 시작하기

Maven 다운받기

Maven Install / Setting

Windows
1. Maven홈페이지에서 maven을 다운받는다 (zip파일)
2. 다운받은 zip파일의 압축을 풀고 C:\ 밑에 옮긴다
3. Windows 환경변수 [MAVEN_HOME : 옮긴path] 지정, [path]에 %MAVEN_HOME%\bin을 추가

Mac
아직...

Linux
아직...

Create Maven Project

1. 터미널 / 커맨드를 실행한다
2. 프로젝트 폴더를 생성 할 경로로 이동한다 (새로운 폴더를 만들지 않는다)
3. 다음 명령어를 실행한다
    $ mvn archetype:create \
      -DarchetypeGroupId=org.apache.maven.archetypes \
      -DgroupId=net.blog.dope \
      -DartifactId=dope-blog
  
    archetypeGroupId : 아직...
    groupId : 기본적인 자바 package
    artifactId : 현 폴더에서 생성할 프로젝트 폴더명
4. 폴더를 확인한다  
dope-blog
     ├ src
     ├ main
        ├ java
           net
              ├ blog
                 ├ dope
                     └ App.java
     ├ test
              ├ java
                  net
                     ├ blog
                        ├ dope
                            └ App.java
     └ pom.xml

5. 각 파일 확인
    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>net.blog.dope</groupId>
  <artifactId>dope-blog</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>takepart-blog</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

   main.java.net.blog.dope.App.java
package net.blog.dope;

/**
 * Hello world!
 *
 */
public class App
{
    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
    }
}

   test.java.net.blog.dope.App.java
package net.blog.dope;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

/**
 * Unit test for simple App.
 */
public class AppTest
    extends TestCase
{
    /**
     * Create the test case
     *
     * @param testName name of the test case
     */
    public AppTest( String testName )
    {
        super( testName );
    }

    /**
     * @return the suite of tests being tested
     */
    public static Test suite()
    {
        return new TestSuite( AppTest.class );
    }

    /**
     * Rigourous Test :-)
     */
    public void testApp()
    {
        assertTrue( true );
    }
}
※ 각 파일의 설명은 생략







참고 : http://javacan.tistory.com/entry/MavenBasic
         http://maven.apache.org/guides/getting-started/index.html#How_do_I_setup_Maven