관리 메뉴

JIE0025

[Tomcat] 톰캣에 WAR 배포하는 방법 본문

Infra/WEB, WAS

[Tomcat] 톰캣에 WAR 배포하는 방법

sdoaolo 2025. 3. 25. 00:03
728x90

 

✅ WAR 파일이란? 

 

war파일은 Web Application Archive의 약자로 

WAS(Web Application Server)에 애플리케이션을 배포하기 위한 파일이다. 

 

 

 

✅ WAR 파일 생성 방법 (Eclipse 기준)


애플리케이션에서 간단하게 war를 생성할 수 있다. 

 

  1. 프로젝트 우클릭
  2. Export 클릭
  3. WAR file 검색 후 선택
  4. 파일 이름 및 저장 경로 지정
  5. Finish 버튼 클릭 → .war 파일 생성 완료

 

  • 루트 경로(/)에 배포하고 싶다면 파일명을   ROOT.war로 생성하면 된다
  • 만약 별도의 톰캣 애플리케이션을 설정하려면 다른 이름으로 만들어도 된다.  (example.war)

 

 

 

 

War 파일 배포 (자동배포) 

톰캣 설치 디렉터리/webapps 아래에  ROOT.war를 복사해 넣어두면,

톰캣 기동시 자동으로 압축이 해제되고, 배포가 이루어진다 ( /ROOT 폴더가 생긴다. )

 

  1. ROOT.war → /webapps/ROOT/로 해제
  2. http://domain:8080/으로 요청 시, 해당 ROOT 애플리케이션이 실행

 

  1. example.war → /webapps/example/로 해제됨
  2. http://domain:8080/example 요청 시 실행

 

 

✅  context 수동 지정 

 


예를들어  example.war를 생성했다고 가정하자.

 

http://domain:8080/으로 요청했는데 example디렉터리가 실행되게 하고 싶다. 

 

 

⚠ Tomcat 공식 권장 방식

 공식문서에 의하면 <Context>요소를 Server.xml에 직접 작성하는 것을 권장하지 않는다고 한다. 

이 파일이 변경되면 톰캣을 재시작해야하기 때문이다. 

 

대신 $CATALINA_BASE/conf/[engine]/[host]/ 경로에 개별적인 .xml 파일을 생성하여

Context를 설정하는 방식을 권장한다고 한다. 

 

 

 

따라서 example.xml을 생성하여 거기에 Context내용을 추가하고 관리하자.

https://tomcat.apache.org/tomcat-9.0-doc/config/context.html?utm_source=chatgpt.com

 

 

 

 

<Context path="[경로]" docBase="[war파일의 이름]"  reloadable="false" > </ContexContext path="[경로]" docBase="[war파일의 이름]"  reloadable="false" > </Contex

 

 

1)  $CATALINA_BASE/conf/Catalina/localhost/   아래에 example.xml을 만든다

2) example.xml에 아래 내용을 작성한다. 

<Context path="/example" docBase="example" reloadable="false" />


여기에서   path="/"로 두면  루트경로로 매핑한다는 의미이다.

>>> http://domain:8080으로 요청 시   ROOT폴더 대신 등록한 example.war가  실행된다

 

 

context path = "/example"로 두고,  war파일을 example로 제작해서 /webapps아래에 두게되면

>>  http://domain:8080/example 으로 요청 시  example 애플리케이션이 동작하게 된다. 

 

 

 


 

references

https://tomcat.apache.org/tomcat-9.0-doc/config/context.html?utm_source=chatgpt.com

 

Apache Tomcat 9 Configuration Reference (9.0.102) - The Context Container

When autoDeploy or deployOnStartup operations are performed by a Host, the name and context path of the web application are derived from the name(s) of the file(s) that define(s) the web application. Consequently, the context path may not be defined in a M

tomcat.apache.org

 

 

 

 

https://www.lifencoding.com/web/28?p=1

https://velog.io/@bi-sz/ApacheTomcat-%ED%86%B0%EC%BA%A3-%EC%84%9C%EB%B2%84-%EC%98%AC%EB%A6%AC%EA%B8%B0