eGovFramework 서버별 resources 분리 방법 / Maven war 빌드 방법

eGovFramework 서버별 resources 분리 방법

resources 폴더 분리 예시

구분 resources 폴더명 프로파일명
개발서버용 resources-dev dev
운영서버 사용자용 resources-service service
운영서버 어드민용 resources-admin admin

resources 폴더 경로

프로젝트폴더/src/main

pom.xml 설정

<build>
  <resources>
    <resource>
        <directory>src/main/resources-${env}</directory>
    </resource>
    <resource>
        <directory>src/main/resources</directory>
    </resource>
  </resources> 
</build>
<profiles>
  <!-- 개발서버 반영용 -->
  <profile>
      <id>dev</id>
      <activation>
          <activeByDefault>true</activeByDefault>
      </activation>
      <properties>
          <env>dev</env>
      </properties>
  </profile>
  <!-- 운영서버 사용자용 -->
  <profile>
      <id>service</id>
      <properties>
          <env>service</env>
      </properties>
  </profile>
  <!-- 운영서버 어드민용 -->
  <profile>
      <id>admin</id>
      <properties>
          <env>admin</env>
      </properties>
  </profile>
</profiles>

pom.xml의 <project> 태그 안에 서버별 resources 폴더 정보를 작성해두면,
클린패키지 설정으로 프로파일명 명시 후 war 빌드 시 구분에 맞는 resources 폴더로 패키징 하게 됩니다.

IntelliJ에서 resources 폴더 변경하여 외장 톰캣 실행 방법

우측 상단 ‘프로젝트명Application’ 클릭 > Edit Configuration… > VM options: -Dspring.profiles.active=프로파일명 입력 > Apply > OK > 상단 Tomcat 오른쪽 ▶ 버튼 클릭


이클립스 Maven war 빌드 방법

서버별 war 빌드 방법

Run > Run Configurations > Maven Build 더블 클릭 > New_confiuration에서 아래와 같이 설정 후 Apply > Run

Name 프로젝트명_서버구분(한글) 입력
Main 탭 Workspace... 눌러서 프로젝트 선택 후
Goals에 'clean package -P 개발서버용/운영사용자용/운영관리자용 프로파일명' 입력
(로컬용은 clean package만 입력합니다.)
JRE 탭 Alternate JRE 선택 후 프로젝트 버전에 맞는 jdk 선택

clean package 설정 후 빌드 된 war는 src/main/resources-프로파일명 폴더의 파일들을 갖게 됩니다.

만들어진 Configurations 우클릭 > Duplicate로 복제 후 각 서버와 서비스 구분별로 하나씩 만들어두고 재사용하면 편합니다.

war 빌드 Failed 시

프로젝트 우클릭 > Run As > Maven Clean으로 target 폴더를 초기화하고 다시 시도하면 됩니다.


IntelliJ Maven war 빌드 방법

서버별 war 빌드 구성 추가

우측 상단 Edit Configurations > 좌측 상단 + 버튼 > Maven > 아래와 같이 설정 후 Apply > OK

Name 프로젝트명_서버구분(한글) 입력
Store as project file 체크해야 .run 폴더에 이름.run.xml이 저장되어서, IntelliJ 재시작 시 삭제되지 않습니다.
Run clean package 입력
Woking directory 자동 완성된 프로젝트명 확인
Profiles 서버 구분에 맞는 프로파일명 입력 (dev 등)

서버별 war 빌드 방법

우측 상단 Run Configurations 목록에서 생성한 war 빌드 구성 선택 > 오른쪽 ▶ 버튼 클릭
또는
우측 Maven View > 하단 Run Configurations > 생성한 war 빌드 구성 더블 클릭

빌드 결과물이 서버 구분에 맞는 properties가 아닌 경우

좌측 상단 File > Project Structure… > Modules > 프로젝트명 > Sources 탭 > 우측에서 Test Resource Folders 삭제 > OK


Maven war 빌드 확인

war 파일 위치

console에 ‘BUILD SUCCESS’가 나오면 프로젝트 폴더 아래의 target 폴더 안에 war 파일이 생성됩니다.

war 파일 resources 정상 확인
target 폴더 안의 war 파일과 같은 위치에 있는 war 압축이 풀린 폴더에서 확인합니다.
WEB-INF/classes 폴더 안에 기존 resources 폴더의 내용들이 패키징 된 것을 볼 수 있습니다.

빌드된 eGovFramework properties 경로 예시

프로젝트명\target\egovframework-all-in-one\WEB-INF\classes\egovframework\egovProps\globals.properties

MainPage URL, DB 연결 정보, fileStorePath 등이 서버와 서비스 구분에 맞는지 확인해야 합니다.

Leave a comment