IT

Tomcat 7.0에서 웹 애플리케이션의 컨텍스트 경로를 설정하는 방법

lottoking 2020. 6. 5. 08:14
반응형

Tomcat 7.0에서 웹 애플리케이션의 컨텍스트 경로를 설정하는 방법


나는 webapp (또는 WAR 파일)의 이름을 ROOT로 바꿀 수 있다는 것을 알고 있지만 IMHO는 끔찍한 방법입니다. 이제 바람둥이 문서를 확인했는데

server.xml 파일에 직접 요소를 배치하지 않는 것이 좋습니다.

그래서 제안한 다른 방법으로 시도했습니다.

개별 컨텍스트 요소는 다음과 같이 명시 적으로 정의 될 수 있습니다. 응용 프로그램 파일 내의 /META-INF/context.xml에있는 개별 파일.

그래서 /META-INF/context.xml다음 코드를 사용하여

<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/"/>

그러나 서버를 다시 시작할 때 배포 한 후에도 여전히 "/"에서 컨텍스트를로드하지 못했습니다. "/<WEB_APP_NAME>"

도움이되는 포인터.


할 수있는 일은 다음과 같습니다.

호출 ROOT.xml파일 추가<catalina_home>/conf/Catalina/localhost/

이 ROOT.xml은 해당 엔진 및 호스트 (Catalina 및 localhost)에 대한 Tomcat 설치의 루트 컨텍스트에 대한 기본 설정을 대체합니다.

ROOT.xml 파일에 다음을 입력하십시오.

<Context 
  docBase="<yourApp>" 
  path="" 
  reloadable="true" 
/>

자, <yourApp>앱 이름입니다 .. :)

이제 응용 프로그램이 기본 응용 프로그램으로 표시되며 http://localhost:8080

그러나 한 가지 부작용이 있습니다. 응용 프로그램이 두 번로드됩니다. 한 번만 localhost:8080및에 한 번 localhost:8080/yourApp. 이 문제를 해결하려면 응용 프로그램을 외부 <catalina_home>/webapps에 놓고 ROOT.xml의 docBase 태그에서 상대 또는 절대 경로를 사용하십시오. 이 같은;

<Context 
  docBase="/opt/mywebapps/<yourApp>" 
  path="" 
  reloadable="true" 
/>

그리고 모든 것이 정상입니다!


다음 은 나를 위해 일한 유일한 솔루션을 따릅니다 . 이것을 conf / server.xml의 호스트 노드에 추가하십시오

<Context path="" docBase="yourAppContextName">

  <!-- Default set of monitored resources -->
  <WatchedResource>WEB-INF/web.xml</WatchedResource>

</Context>

Tomcat server.xml 파일로 이동하여 경로를 비워 둡니다.


Tomcat 9.0에서는 다음에서 변경해야합니다. server.xml

<Context docBase="web" path="/web" reloadable="true" source="org.eclipse.jst.jee.server:web"/>

<Context docBase="web" path="" reloadable="true" source="org.eclipse.jst.jee.server:web"/>

이 작은 코드는 가상 호스트를 사용하여 나를 위해 일했습니다.

<Host name="my.host.name" >
   <Context path="" docBase="/path/to/myapp.war"/>
</Host>

가장 빠르고 최상의 솔루션 일 수 있습니다. <TOMCAT_INSTALL_DIR>/conf/Catalina/localhost/ROOT.xml

<Context 
  docBase="/your_webapp_location_directory" 
  path="" 
  reloadable="true" 
/>

그리고 귀하의 웹앱은 http://<host>:<port>/


한 달 동안이 문제에 직면했습니다 .server.xml에 컨텍스트 태그를 넣는 것은 안전하지 않습니다. 다른 모든 호스트에 배포하는 컨텍스트 요소에 영향을 미칩니다. 큰 응용 프로그램의 경우 연결 오류가 발생하여 격리가 잘 이루어지지 않습니다. .com / domain1Folder !! 또한 데이터베이스 세션 연결이 두 번로드되었습니다! 다른 방법은 컨텍스트 태그가있는 ROOT.xml 파일을 전체 경로와 함께 넣는 것입니다.

 <Context path="" docBase="/var/lib/tomcat7/webapps/ROOT" />

conf / catalina / webappsfoldername에서 warapp를 webappsfoldername 내에 ROOT.war로 배포하고 호스트와 같은 호스트를 지정하십시오.

 <Host name="domianname"  appBase="webapps2" unpackWARs="true"  autoDeploy="true"  xmlValidation="false" xmlNamespaceAware="false" >

        <Logger className="org.apache.catalina.logger.FileLogger"
               directory="logs"  prefix="localhost_log." suffix=".txt"
          timestamp="true"/>
</Host>

In this approach also for same type apps user sessions has not good isolation ! you may inside app1 if app1 same as app2 you may after login by server side session automatically can login to app2 ?! So you have to keep users session in client side cache and not with jsessionid ! we may change engine name from localhost to solve it. but let say playing with tomcat need more time than play with other cats!


It's not recommended to update the server configuration like server.xml or ROOT.xml.

You can put a context.xml configuration file under your web-application META-INF directory, with the context path setting included. This will override the default server setting?

i.e.:

<Context docBase="yourAppName" path="/yourAppPath" reloadable="true">

<Context docBase="yourAppName" path="" reloadable="true">

go to Tomcat server.xml file and set path blank


Tomcat 8 : After many searches this is only working code: in server.xml

<!-- Set /apple as default path -->
    <Host name="localhost"  appBase="webapps"
         unpackWARs="true" autoDeploy="true">
     <Context path="" docBase="apple">
         <!-- Default set of monitored resources -->
         <WatchedResource>WEB-INF/web.xml</WatchedResource>
     </Context>
    </Host>

Restart Tomcat, make sure when you access 127.0.0.1:8080, it will display the content in 127.0.0.1:8080/apple

My project was java web application witch created by netbeans ,I set context path in project configuration, no other thing, even I put apple.war in webapps folder.


For me both answers worked.

  1. Adding a file called ROOT.xml in /conf/Catalina/localhost/
<Context
    docBase="/tmp/wars/hpong"
  path=""
  reloadable="true"
/>
  1. Adding entry in server.xml
<Service name="Catalina2">
    <Connector port="8070" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8743" />
    <Engine name="Catalina2" defaultHost="localhost">
        <Host name="localhost"
            unpackWARs="true" autoDeploy="true">
            <Context path="" docBase="/tmp/wars/hpong"  reloadable="true">
                <WatchedResource>WEB-INF/web.xml</WatchedResource>
            </Context>
      </Host>
    </Engine>
</Service>

Note: when you declare docBase under context then ignore appBase at Host.

  1. However I have preferred converting my war name as ROOT.war and place it under webapps. So now unmatched url requests from other wars(contextpaths) will land into this war. This is better way to handle ROOT ("/**") context path.

The second option is (double) loading the wars from Webapps folder as well. Also it only needs uncompressed war folder which is a headache.


In Tomcat 8.X ,under tomcat home directory /conf/ folder in server.xml you can add <Context> tag under <Host> tag as shown below . But you have to restart the server in order to take effect

  <Host name="localhost"  appBase="webapps"
        unpackWARs="true" autoDeploy="true">

     <Context docBase="${catalina.base}\webapps\<Your App Directory Name>" path="<your app path you wish>" reloadable="true" />
  </Host>

OR if you are using Tomcat 7.X you can add context.xml file in WEB-INF folder in your project . The contents of the file i used is as shown . and it worked fine for me . you don't have to restart server in this case .

<?xml version="1.0" encoding="UTF-8"?>

<Context docBase="${catalina.base}\webapps\<My App Directory Name>" path="<your app path you wish>" reloadable="true" />

Simplest and flexible solution is below: Inside ${Tomcat_home}/config/server.xml

Change the autoDeploy="false" deployOnStartup="false" under Host element like below This is must.

<Host name="localhost"  appBase="webapps"
        unpackWARs="true" autoDeploy="false" deployOnStartup="false">

Add below line under Host element.

<Context path="" docBase="ServletInAction.war"  reloadable="true">
            <WatchedResource>WEB-INF/web.xml</WatchedResource>
        </Context>

With the above approach we can add as many applications under webapps with different context path names.


The below trick worked for me.

1) Comment/delete the below configuration from server.xml file (inside conf folder) of tomcat.

2) Delete the existing ROOT folder (If any) residing inside tomcat webapps folder. And rename your war (e.g: test.war ) file to ROOT.war.

Remember that while renaming war file to ROOT.war "ROOT" should be in caps.

Limitation: You can deploy only one application inside one tomcat instance.

참고URL : https://stackoverflow.com/questions/7276989/how-to-set-the-context-path-of-a-web-application-in-tomcat-7-0

반응형