본문 바로가기

open source/maven & hudson

메이븐 + 스프링 + ibatis + 허드슨 연동 구축 2탄 - 메이븐 폴더 구조 변경하기

나는 메이븐은 책을 보고 지금으로 부터 1년전에 공부를 했었다..

골이란게 있었고.. 페이즈란게 있었던거 같았고.. 중앙 저장소.. 사내 저장소.. 등등의 내용이 어렴풋이 기억이 난다. 그 기억을 모두 잃어버릴까 두려워 다시 공부를 한다.

허드슨은 구글 검색을 하여 대충 실습하며 동작 방식을 아주 조금 이해 했다. 메이븐과 허드슨을 사용하여 프로젝트를 구성해 보려고 한다.


2탄. 메이븐 폴더구조 변경 하기


-----------------------------------------------------------------------------------------------------------------


왠지 모르게 webapp라는 폴더 구조가 마음에 들지 않는다.

pom.xml을 수정해서 레이아웃 구조를 변경해보자..



자바 버전 변경하기


그 전에 메이븐 프로젝를 생성하니 자바버전이 1.5로 되어있다.


이렇게....


나는 1.6으로 하고 싶다..1.6으로 변경하자.

옵션에서 project facets 메뉴의 자바 버전 1.5 -> 1.6 으로 변경.


pom.xml에 추가 (자바 버전 변경, 인코딩 변경)

                 <plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-compiler-plugin</artifactId>

<configuration>

<source>1.6</source>

<target>1.6</target>

<encoding>UTF-8</encoding>

</configuration>

</plugin>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-resources-plugin</artifactId>

<configuration>

<encoding>UTF-8</encoding>

</configuration>

</plugin>  




레이아웃 변경하기


우리 메이븐 프로젝트의 pom.xml 위에 super pom.xml 이 존재 한다고 했다.


layout 정보 -> http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html

pom documentaion -> http://maven.apache.org/guides/introduction/introduction-to-the-pom.html


위의 경로에 가면 확인 가능하다. pom documentaion 가보면 

The snippet below is the Super POM for Maven 2.1.x. 을 확인 할 수 있다.


이런 내용의...

<plugin> <artifactId>maven-war-plugin</artifactId> <version>2.1-alpha-2</version> 

</plugin> 



나는 webapp 의 경로가 마음에 들지 않는다.

우리의 pom.xml에서 변경 하자.

   

        <plugin>

         <artifactId>maven-war-plugin</artifactId>

         <configuration>

         <warSourceDirectory>${basedir}/webapp</warSourceDirectory>

        </configuration>

       </plugin>



위와 같이 변경 하고 나니 project에 액박이 뜬다.



프로젝트를 마우스 오른쪽 버튼 클릭 -> maven 메뉴 -> update project 를 클릭 해 주면 pom.xml의 내용으로 프로젝트가 변경된다.


최종 프로젝트의 레이아웃이다.



webapp 폴더의 위치가 변경 되었으며, 기존의 webapp 폴더는 삭제하자.

java , resource 디렉토리의 위치도 위와 같은 방법으로 변경 가능하다. 사용하기 편한 레이아웃을 구성하여 사용하도록 하자..


마지막으로 WEB-INF가 존재 하지 않아서 webapp 폴더안에 WEB-INF 폴더를 생성하고 web.xml 파일을 생성하였다.


다음 시간에는 spring + ibatis 셋팅을 해보겠다.



[ 참고 ] 메이븐 최상위 pom.xml 

 - http://maven.apache.org/guides/introduction/introduction-to-the-pom.html 의 내용

메이븐 사이트에서 긁어왔다.

<project>

  <modelVersion>4.0.0</modelVersion>

  <name>Maven Default Project</name>


<!-- 저장소 설정 영역 -->

  <repositories>

    <repository>

      <id>central</id>

      <name>Maven Repository Switchboard</name>

      <layout>default</layout>

      <url>http://repo1.maven.org/maven2</url>

      <snapshots>

        <enabled>false</enabled>

      </snapshots>

    </repository>

  </repositories>

<!--// 저장소 설정 영역 끝-->


<!-- 플러그인 저장소 설정 영역 -->

  <pluginRepositories>

    <pluginRepository>

      <id>central</id>

      <name>Maven Plugin Repository</name>

      <url>http://repo1.maven.org/maven2</url>

      <layout>default</layout>

      <snapshots>

        <enabled>false</enabled>

      </snapshots>

      <releases>

        <updatePolicy>never</updatePolicy>

      </releases>

    </pluginRepository>

  </pluginRepositories>

<!--// 플러그인 저장소 설정 영역 끝-->



<!-- 빌드 설정 영역, 디렉토리 구조, 플러그인 설정 -->

  <build>

    <directory>${project.basedir}/target</directory>

    <outputDirectory>${project.build.directory}/classes</outputDirectory> //-컴파일된 서비스 자바 class 의 위치

    <finalName>${project.artifactId}-${project.version}</finalName> 

    <testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory> //-컴파일된 테스트 자바 class 의 위치

    <sourceDirectory>${project.basedir}/src/main/java</sourceDirectory> //-서비스 자바 소스의 위치

    <scriptSourceDirectory>src/main/scripts</scriptSourceDirectory> //-스크립트 위치

    <testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory> //-테스트 소스 자바의 위치

    <resources>

      <resource>

        <directory>${project.basedir}/src/main/resources</directory> //-서비스 자바 소스에서 사용하는 리소스 파일 위치

      </resource>

    </resources>

    <testResources>

      <testResource>

        <directory>${project.basedir}/src/test/resources</directory> //-테스트 자바 소스에서 사용하는 리소스 파일 위치

      </testResource>

    </testResources>

<!-- 라이브러리 설정 영역 -->

   <pluginManagement>

       <plugins>

         <plugin>

           <artifactId>maven-antrun-plugin</artifactId>

           <version>1.3</version>

         </plugin>       

..... 생략

       </plugins>

     </pluginManagement>

<!--// 라이브러리 설정 영역 끝-->

  </build>

<!--// 빌드 설정 영역 끝, 디렉토리 구조, 플러그인 설정 -->


<!-- 메이븐 리포팅 설정 영역 -->

     //메이븐은 프로젝트 정보에 대한 기본 report 뿐만 아니라 플러그인 설정을 

     //통해 emma, JavaDoc 등의 report 생성 기능을 제공한다. 

  <reporting>

    <outputDirectory>${project.build.directory}/site</outputDirectory>

  </reporting>

<!--// 메이븐 리포팅 설정 영역 끝 -->


<!-- 프로파일 설정 영역 -->

  <profiles>

    <profile>

      <id>release-profile</id>


      <activation>

        <property>

          <name>performRelease</name>

          <value>true</value>

        </property>

      </activation>


      <build>

        <plugins>

          <plugin>

            <inherited>true</inherited>

            <groupId>org.apache.maven.plugins</groupId>

            <artifactId>maven-source-plugin</artifactId>

            <executions>

              <execution>

                <id>attach-sources</id>

                <goals>

                  <goal>jar</goal>

                </goals>

              </execution>

            </executions>

          </plugin>

          <plugin>

            <inherited>true</inherited>

            <groupId>org.apache.maven.plugins</groupId>

            <artifactId>maven-javadoc-plugin</artifactId>

            <executions>

              <execution>

                <id>attach-javadocs</id>

                <goals>

                  <goal>jar</goal>

                </goals>

              </execution>

            </executions>

          </plugin>

          <plugin>

            <inherited>true</inherited>

            <groupId>org.apache.maven.plugins</groupId>

            <artifactId>maven-deploy-plugin</artifactId>

            <configuration>

              <updateReleaseInfo>true</updateReleaseInfo>

            </configuration>

          </plugin>

        </plugins>

      </build>

    </profile>

  </profiles>

<!--// 프로파일 설정 영역 끝 -->

</project> 


최상위 pom.xml을 대충 의미하는 영역을 알 수 있을것 같다. 

최상위 pom.xml 을 보면 webapp 폴더 내용 구조 정의 부분을 찾아 볼 수가 없다.

webapp의 디렉토리 구조는 maven-war-plugin 관리한다.

설정 하려면..

 <plugin>

       <artifactId>maven-war-plugin</artifactId>

               <configuration>

         <warSourceDirectory>${basedir}/webapp</warSourceDirectory>

               </configuration>

</plugin>

허드슨을 이용하여 배포를 하기 위해서는 profile 정의 부분을 알아봐야 한다.

배포할 때 자세히 공부하도록 하자.