Eclipse - Webプロジェクトのコンテキストルートを変更する方法

Eclipse – Webプロジェクトのコンテキストルートを変更する方法

EclipseでWebプロジェクトを実行またはデバッグする場合、プロジェクト名はデフォルトのコンテキストルートになります。 たとえば、「springmvc」という名前のプロジェクトの場合、デフォルトのコンテキストルートは

http://localhost:8080/springmvc

テストされた技術:

  1. Eclipse 4.4

  2. Eclipse Tomcatサーバープラグイン

  3. メーベン3

  4. Gradle 2.0

Note
コンテキストルートは、デプロイされたWebアプリケーションのURLを示します。

http://localhost:8080/{context_root}

このチュートリアルでは、Eclipse IDEでWebプロジェクトのコンテキストルートを更新するいくつかの方法を紹介します。

1. Eclipse – Webプロジェクトの設定

eclipse-context-root-solution1

1.1 Right click on the project, select Properties, Web Project Settings, update the context root here.
1.2 Remove your web app from the server and add it back. コンテキストルートを更新する必要があります。
1.3手順2が失敗した場合は、サーバーを削除し、新しいサーバーを作成して、Webアプリを追加し直します。

新しいコンテキストルート:http://localhost:8080/abc

2. Eclipse – Webモジュール

eclipse-context-root-solution2

2.1 Double click on the Eclipse server plugin.
2.2 Clicks on the Modules tab.
2.3 Update the Path.
2.4 Done. サーバーを再起動してください。

新しいコンテキストルート:http://localhost:8080/abc

3. Maven Eclipseプラグイン

3.1 Define the new context root in wtpContextName.

pom.xml

    
        org.apache.maven.plugins
        maven-eclipse-plugin
        2.9
        
            2.0
            abc
        
    

3.2 Issue below command to recreate the Eclipse settings.

$ mvn eclipse:cleanEclipse eclipse:eclipse

4. Gradle Eclipseプラグイン

4.1 Define the eclipse wtp settings.

build.gradle

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'eclipse-wtp'

//For Eclipse IDE only
eclipse {

  wtp {
    component {
      contextPath = 'abc'
    }

  }
}

4.2 Issue below command to recreate the Eclipse settings.

$ gradle clenEclipse eclipse