2010년 7월 25일 일요일

Maven WTP Project 생성하기

1. CMD를 실행.

2. 워크스페이스로 이동한다.

3. 워크스페이스 폴더에서 다음과 같이 입력한다.

 

mvn archetype:generate -DgroupId=package.name -DartifactId=ProjectName

-DarchetypeArtifactId=maven-archetype-webapp

위와 같이 입력하면 워크스페이스에 ProjectName 이라는 폴더가 생기면서 프로젝트 폴더의 구색을 갖추게 된다.

 

Maven 기반 웹 프로젝트의 기본 디렉토리는 src/main/webapp이다. webapp 디렉토리는 자바 기반 웹 애플리케이션의 기본 웹 디렉토리 구조를 따른다. Maven Archetype에 의하여 기본으로 생성되는 war 프로젝트는 자바 소스 코드를 관리하기 위한 src/main/java, src/test/java 디렉토리를 생성하지 않는다. 따라서 웹 자원과 자바 소스 코드를 같이 관리하려면 src/main/java, src/test/java 디렉토리를 추가해야한다.

 

그 다음으로 할일은 maven 프로젝트의 pom.xml 을 수정해야 한다.

 

pom.xml 파일은 maven 프로젝트의 설정을 관리한다.

 

여튼,

 

메이븐으로 만들어진 기본 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>net.narsha</groupId>
  <artifactId>Address</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>Address Maven Webapp</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>net.narsha</groupId>
  <artifactId>Address</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>Address Maven Webapp</name>
  <url>http://maven.apache.org</url>
 <properties>
   <webapp.context>/</webapp.context>
   <maven.compiler.source>1.5</maven.compiler.source>
   <maven.compiler.target>1.5</maven.compiler.target>
   <maven.compiler.encoding>utf-8</maven.compiler.encoding>   
  </properties> 
 
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
   <finalName>Address</finalName>
   <plugins>
    <plugin>
     <artifactId>maven-compiler-plugin</artifactId>
     <configuration>
      <source>${maven.compiler.source}</source>
      <target>${maven.compiler.target}</target>
      <encoding>${maven.compiler.encoding}</encoding>
     </configuration>
    </plugin>
    <plugin>
        <artifactId>maven-eclipse-plugin</artifactId>
      <version>2.4</version>
      <configuration>
       <wtpContextName>${webapp.context}</wtpContextName>
       <downloadSources>true</downloadSources>
       <downloadJavadocs>true</downloadJavadocs>
       <wtpversion>1.5</wtpversion>
      </configuration>     
     </plugin>
    </plugins>
   </build>
</project>

 

위와같이 설정을 추가했으면 다시 cmd 로 돌아가 방금 생성한 프로젝트폴더로 이동한 다음

다음과 같이 입력한다.

 

mvn eclipse:clean eclipse:eclipse

 

이 명령은 Maven 기반의 프로젝트를 이클립스에서 실행할 수 있도록 만들어 준다.

입력 후 실행을 하고 BUILD SUCCESS 가 출력된다면, 빌드에 성공한것이다.

 

그 다음, 할일은 이클립스에서 Import 를 해주는데 General - Existing Projects into Workspace 로 들어간 뒤

Select root directory 에서 메이븐 프로젝트를 선택 한 후 Finish 를 누르면 메이븐 프로젝트 -> 이클립스 프로젝트로 완성이 된다.

 

 

댓글 없음:

댓글 쓰기