티스토리 뷰





테스트 환경

OS : Windows 10

Tool : Eclipse Java EE IDE for Web Developers 

         Version: Kepler Service Release 2

Framework : Spring 3.2.9 (전자정부프레임워크)



메이븐 빌드시 환경별 소스 구분하기 (기록용으로 남김)




1. 빌드시 구분되어질 파일 생성한 후 서버별 내용을 수정한다.

ex) src/main/resources/logback.xml

    src/main/resources/logback.xml_dev (개발용)

    src/main/resources/logback.xml_prod (운영용)

    JLBlog/target/classes/properties/jlblog.properties

    JLBlog/target/classes/properties/jlblog.properties_dev (개발용)

    JLBlog/target/classes/properties/jlblog.properties_prod (운영용)



2. pom.xml  다음 내용 추가

 <properties>    

  <project.build.outputDirectory>JLBlog/target/classes </project.build.outputDirectory>

  <project.resource.directory>src/main/resources</project.resource.directory>

 </properties>


 <profiles>

  <profile>

   <id>dev</id>

   <build>

    <plugins>

     <plugin>

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

 <executions>

  <execution>

<phase>compile</phase>

<goals>

<goal>run</goal>

</goals>

<configuration>

<tasks>

 <delete>

  <fileset dir="${project.build.outputDirectory}" includes="**/logback.xml*,**/jlblog.properties*" />

 </delete>

 <copy file="${project.resource.directory}/properties/jlblog.properties_dev"

tofile="${project.build.outputDirectory}/properties/jlblog.properties" />

 <copy file="${project.resource.directory}/logback.xml_dev" 

                                        tofile="${project.build.outputDirectory}/logback.xml" />

</tasks>

</configuration>

  </execution>

 </executions>

</plugin>

<plugin>

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

 <version>2.6</version>

 <configuration>

  <packagingExcludes>META-INF/context.xml</packagingExcludes>

 </configuration>

</plugin>

</plugins>

   </build>

  </profile>

  <profile>

   <id>prod</id>

   <build>

    <plugins>

     <plugin>

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

 <executions>

  <execution>

<phase>compile</phase>

<goals>

<goal>run</goal>

</goals>

<configuration>

<tasks>

 <delete>

  <fileset dir="${project.build.outputDirectory}" includes="**/logback.xml*,**/jlblog.properties*" />

 </delete>

 <copy file="${project.resource.directory}/properties/jlblog.properties_prod"

tofile="${project.build.outputDirectory}/properties/jlblog.properties" />

 <copy file="${project.resource.directory}/logback.xml_prod" 

                                        tofile="${project.build.outputDirectory}/logback.xml" />

</tasks>

</configuration>

  </execution>

 </executions>

</plugin>

<plugin>

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

 <version>2.6</version>

 <configuration>

  <packagingExcludes>META-INF/context.xml</packagingExcludes>

 </configuration>

</plugin>

</plugins>

   </build>

  </profile>

 </profiles> 



<id> : dev / prod 빌드시 구분하기 위한 id


<delete> : 해당 위치에 있는 logback.xml 과 jlblog.properties 파일을 삭제

<copy> : 해당 위치에 있는 파일을 logback.xml 과 jlblog.properties 파일명으로 복사


<packagingExcludes> : 빌드시 해당 파일은 포함하지 않음




3. 메이븐 빌드하기

 - 개발서버용(dev) : 

    프로젝트 우클릭 -> Run As -> Maven Build -> 팝업창 Goals란에 clean package -Pdev -X 입력 후 Run

 - 운영서버용(prod) :

    프로젝트 우클릭 -> Run As -> Maven Build... -> 팝업창 Goals란에 clean package -Pprod -X 입력 후 Run


4. 확인

 - 생성된 war을 압축해제 한 후 해당 파일의 내용을 확인

 - 서버 반영 






                          



댓글