How to change context root of a dynamic web project in Eclipse?

后端 未结 13 2513
一整个雨季
一整个雨季 2020-11-22 12:59

I developed a dynamic web project in Eclipse. I can access the app through my browser using the following URL:

http://localhost:8080/MyDynamicWebApp


        
相关标签:
13条回答
  • 2020-11-22 13:07

    I just wanted to add that if you don't want your application name in the root context at all, you and just put "/" (no quotes, just the forward slash) in the Eclipse --> Web Project Settings --> Context Root entry

    That will deploy the webapp to just http://localhost:8080/

    Of course, this will cause problems with other webapps you try to run on the server, so heads up with that.

    Took me forever to piece that together... so even though this post is 8 years old, hopefully this will still help someone!

    0 讨论(0)
  • 2020-11-22 13:09

    Setting the path to nothing in the Eclipse web modules edit dialog enabled me to access the project without any path component in the URL (i.e. ROOT)

    You can reach the web modules edit dialog by pressing F3 if you select Tomcat in the "Servers" view or by double clicking on it.

    Some screenshots:

    0 讨论(0)
  • 2020-11-22 13:11

    If the project is maven, change the "finalName" in pom.xml and Update Project as Maven.This worked for me.

    0 讨论(0)
  • 2020-11-22 13:15

    In Glassfish you must also change the file WEB-INF/glassfish-web.xml

    <glassfish-web-app>
        <context-root>/myapp</context-root>
    </glassfish-web-app>
    

    So when you click in "Run as> Run on server" it will open correctly.

    0 讨论(0)
  • 2020-11-22 13:16

    After changing the context root in project properties you have to remove your web application from Tomcat (using Add and Remove... on the context menu of the server), redeploy, then re-add your application and redeploy. It worked for me.

    If you are struck you have another choice: select the Tomcat server in the Servers view. Double clicking on that server (or selecting Open in the context menu) brings a multipage editor where there is a Modules page. Here you can change the root context of your module (called Path on this page).

    0 讨论(0)
  • 2020-11-22 13:17

    If using maven java ee 7/8 enterprise application, need to edit the pom.xml of the EAR project

    <build>
        <plugins>
            ...
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ear-plugin</artifactId>
                <version>2.8</version>
                <configuration>
                    <version>6</version>
                    <defaultLibBundleDir>lib</defaultLibBundleDir>
                    <modules>
                        <webModule>
                            <groupId>com.sample</groupId>
                            <artifactId>ProjectName-web</artifactId>
                            <contextRoot>/myproject</contextRoot>
                        </webModule>
                    </modules>
                </configuration>
            </plugin>
            ...
        </plugins>
    </build>
    
    0 讨论(0)
提交回复
热议问题