score:343

Accepted answer

i'm sure you've moved on by now, but i thought i'd answer anyway.

some of these answers give workarounds. what actually must happen is that you clean and re-publish your project to "activate" the new uri. this is done by right-clicking your server (in the servers view) and choosing clean. then you start (or restart it). most of the other answers here suggest you do things that in effect accomplish this.

the file that's changing is workspace/.metadata/.plugins/org.eclipse.wst.server.core/publish/publish.dat unless, that is, you've got more than one server in your workspace in which case it will be publishn.dat on that same path.

hope this helps somebody.


not sure if this is proper etiquette or not — i am editing this answer to give exact steps for eclipse indigo.

  1. in your project's properties, choose web project settings.

  2. change context root to app.

    screen shot of eclipse project properties web project settings

  3. choose window > show view > servers.

  4. stop the server by either clicking the red square box ("stop the server" tooltip) or context-click on the server listing to choose "stop".

  5. on the server you want to use, context-click to choose "clean…".

    enter image description here

  6. click ok in this confirmation dialog box.

    screenshot of dialog asking to update server configuration to match the changed context root

now you can run your app with the new "app" url such as:

http://localhost:8080/app/

doing this outside of eclipse, on your production server, is even easier --> rename the war file. export your vaadin app as a war file (file > export > web > war file). move the war file to your web server's servlet container such as tomcat. rename your war file, in this case to app.war. when you start the servlet container, most such as tomcat will auto-deploy the app, which includes expanding the war file to a folder. in this case, we should see a folder named app. you should be good to go. test your url. for a domain such as *example.com" this would be:

http://www.example.com/app/

vaadin toolkit programmers may need to rebuild their widget set if using visual add ons.

score:0

in the java project, open .settings folder. there locate the file named "org.eclipse.wst.common.component" . change tag <wb-module deploy-name="new_name"> .

also you may want to change context root in project properties

score:0

if using eclipse to deploy your application . we can use this maven plugin

<plugin>
    <groupid>org.apache.maven.plugins</groupid>
    <artifactid>maven-eclipse-plugin</artifactid>
    <version>2.10</version>
    <configuration>
        <wtpversion>2.0</wtpversion>
        <wtpcontextname>newcontextroot</wtpcontextname>
    </configuration>
</plugin>

now go to your project root folder and open cmd prompt at that location type this command :

mvn eclipse:eclipse -dwtpversion=2.0

you may need to restart eclipse , or in server view delete server and create agian to see affect. i wonder this exercise make sense in real life but works.

score:0

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>

score:0

i'm there are some alternate resource... but the programmatically way will be by changing the server.xml file from your server .....

this is how a real world project is configured ....change the path in context.

<context docbase="projectname" path="/reachingpath" reloadable="true" source="org.eclipse.jst.jee.server:projectname"/></host>

score:2

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.

score:2

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!

score:4

if the project is maven, change the "finalname" in pom.xml and update project as maven.this worked for me.

score:6

apache tomcat keeps the project context path in server.xml path. for each web project on eclipse, there is tag from there you can change it.
suppose, there are two or three project deployed on server. for each one context path is stored in . this tag is located on server.xml file within server created on eclipse.

i have one project for there on context root path in server is:

<context docbase="test" path="/test" reloadable="true" source="org.eclipse.jst.jee.server:test1"/>

this path represents context path of your web application. by changing this path, your web app context path will change.

score:6

i know the answer has been accepted already. but, just in case anyone using maven wants to achieve the same thing, just set the finalname in the maven build to whatever name you want to give and do a maven -> update project

<build>
    <finalname><any-name></finalname>
    <plugins><provide-plugins-needed></plugins>
<build>

score:10

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:

score:17

i tried out solution suggested by russ bateman here in the post

http://localhost:8080/myapp to http://localhost:8080/somepath/myapp

but didnt worked for me as i needed to have a *.war file that can hold the config and not the individual instance of server on my localmachine.

reference

in order to do that i need jboss-web.xml placed in web-inf

<?xml version="1.0" encoding="utf-8"?>
 <!--
copyright (c) 2008 object computing, inc.
all rights reserved.
-->
<!doctype jboss-web public "-//jboss//dtd web application 4.2//en"
"http://www.jboss.org/j2ee/dtd/jboss-web_4_2.dtd">

  <jboss-web>
  <context-root>somepath/myapp</context-root>
  </jboss-web>

score:24

if you are running tomcat from eclipse, it doesn't use the configuration from your actual tomcat installation. it uses the tomcat configuration that it created and stored under "servers" project. if you view your eclipse workspace, you should see a project called "servers". expand that "servers" project and you will come across server.xml. open this file and scroll all the way to the bottom, and you should see something like this:-

<context docbase="abc" path="/abc" reloadable="true" source="org.eclipse.jst.jee.server:abc"/>

here, you can just change your project context path to something else.

hope this helps.

score:33

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).


Related Query

More Query from same tag