Back-end/JAVA,Spring

eclipse-maven연동 m2e+wtp 사용시 ContextRoot 변경되는 문제 해결

cheersHena 2023. 1. 10. 20:19
반응형
이클립스과 메이븐 연동은 개발자에게 편리함을 제공한다.
하지만 .settings의 자동변화에 종종 삽질을 하게됨.
 
이번에 겪은 삽질은  Dynamic Web Projects와 M2E 통합으로 인해 메이븐 업데이트시, 
.settings/org.elipse.wst.common.component 파일의 <property name = "context-root" value="/"/>
의 값이 자동으로 변경된다는 점이다. 

 

 

ContextRoot 고정시키는 방법 

이클립스 내에서 m2e-wtp플러그인을 사용하여 웹프로젝트를 관리할 때 다음과 같이 context root가 관리된다. 
  1. 기본적으로 m2e-wtp는 maven-war-plugin환경에 정의된 <warName>값으로부터 독립된 웹 애플리케이션의 context root가 적용된다. 
<plugin>
  <artifactId>maven-war-plugin</artifactId>
  <version>1.2</version>
  <configuration>
    <warName>myWebapp</warName>
  </configuration>
</plugin>
 
2. 설정에 값이 지정되어 있지 않다면 war 프로젝트의 <build> 태그에 정의된 <fileName>이 적용된다.
즉, http://localhost:8080/myWebapp/ 와 같이 접근하겠다면, 다음과 같이 정의한다.
<project>
 <groupId>group.bar</groupId> 
 <artifactId>web-project<artifactId> 
 <version>1.0.0-SNAPSHOT</version> 
 <packaging>war</packaging> 
 <build> 
   <finalName>myWebapp</finalName> 
   ...
 </build>
</project>
 
3. 마지막으로 pom.xml 파일안에 custom property를 설정하여  WTP에서 사용할 context root를 변경할 수 있다. 
pom.xml 파일의 <properties> 태그 내 <m2eclipse.wtp.contextRoot>를 정의하면 된다. 
m2eclipse.wtp.contextRoot 앞의 warName, finalName보다 높은 우선순위로 동작한다. 
 
<project>
   ...
 <properties> <m2eclipse.wtp.contextRoot>myWebapp</m2eclipse.wtp.contextRoot>
   ...
 </properties>
</project>
 
 
반응형