■ maven의 필터링은 리소스파일(예를들어 spring의 설정파일)안에 변수를 선언하고 빌드시에 각 빌드환경에 맞게 변수를 치환할 수 있다. ${…} 구분자로 표시하고 커맨드 라인에서 입력할수도 있고 pom.xml에서 속성으로 지정해서 입력할 수도 있다.
■ 참조
Apache Maven Project – Filtering
■ pom.xml의 속성등록 후 치환
1. pom.xml에서 name을 My Resource…로 지정하고 src/main/resources의 filtering속성을 true로 선언한다.
<project> ... <name>My Resources Plugin Practice Project</name> ... <build> ... <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> ... </resources> ... </build> ... </project>
2. 그리고 src/main/resources 디렉토리 안에 임의의 파일 hello.txt를 만들고 ‘${name}’를 입력한다.
${name}
3. 빌드를 하면 target 디렉토리안에 생성된 hello.txt의 ${name}은 My Resources Plugin Practice Project로 치환되어있음을 확인할 수 있다. pom.xml안에 변수 지정은 project태그 바로 아래에 지정해도 되고 properties 태그 안에 지정도 가능하다.
■ 커맨드라인에서 maven실행시 변수 지정은 -D옵션으로 지정가능하다.
mvn clean install -Dname="world"
■ 동일한 프로젝트에 필터링되어야 하는 resource디렉토리와 필터링되지 않아야 하는 resource디렉토리가 동시에 존재한다면 필터링되어야 하는 디렉토리는 아래와 같이 filtering true를 추가하면 된다.
<project> ... <name>My Resources Plugin Practice Project</name> ... <build> ... <resources> <resource> <!-- 필터링되어야 할 디렉토리 --> <directory>src/main/resources1</directory> <filtering>true</filtering> </resource> <resource> <!-- 필터링 되지 않아야 할 디렉토리 --> <directory>src/main/resources2</directory> </resource> ... </resources> ... </build> ... </project>
[/code]
■ 필터링되어야 하는 변수/속성이 많다면 속성파일에 지정도 가능하다. 아래와 같이 filter.properties파일을 생성하고 파일내용에 ‘name=value’형식으로 입력하고 maven빌드를하면 name이 value로 치환된다.
<project> ... <name>My Resources Plugin Practice Project</name> ... <build> ... <filters> <filter>src/main/resources/filter.properties</filter> </filters> ... </build> ... </project>
filter.properties의 내용 name3=Xman
- Tomcat 시작시 ServletContextListener를 통한 mySQL 접속 2018년 5월 8일
- spring mybatis mysql 연결 예제 2018년 5월 4일
- No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? 2017년 12월 4일
- maven filtering – 메이븐 필터링 2016년 10월 24일
- maven profiles – 개발/운영 환경별 빌드 2016년 10월 24일
- maven pom.xml에서 로그 출력하기 2016년 5월 30일
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 2016년 5월 2일
- JUnit Controller Test java.lang.NoClassDefFoundError: javax/servlet/SessionCookieConfig 2016년 3월 22일
- Maven skipTests – Maven JUnit 테스트 안하기 2016년 3월 18일
- maven compile option -Xlint:deprecation 2016년 3월 17일
- Maven encoding 2016년 3월 17일
- TIBCO ActiveSpace Eclipse Maven 2016년 3월 16일
- Jetty Maven Plugin 2016년 3월 9일
- java.lang.UnsupportedClassVersionError: org/eclipse/jetty/maven/plugin/JettyRunMojo : Unsupported major.minor version 52.0 2016년 3월 9일
- java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet 2016년 2월 19일
- eclipse maven 디버그(debug) 모드로 빌드 2014년 11월 21일
- No Spring WebApplicationInitializer types detected on classpath 에러 2014년 11월 21일
- org.apache.ibatis.binding.BindingException 디버깅 2014년 11월 11일
- maven-war-plugin webXml, 개발 환경별 web.xml 관리 2014년 11월 10일
- 명령행 모드 메이븐 프로젝트 생성하기 2014년 9월 17일
- eclipse maven tomcat 자동 재시작 2014년 9월 13일