1

In Eclipse Oxygen I have set up a Web project (facets Dynamic Web Module, Java & JavaScript) with the name MyProject.

When I start up Eclipse's Tomcat (Version 8.5) I can view the site under the project URL http://localhost:8080/MyProject/. So far so good. But how can I configure the Eclipse project that the server's base URL http://localhost:8080 redirects to the project URL?

Bonus question: Is there a way to change the path in the URL without changeing the project name, so that the project URL is, say, http://localhost:8080/FancyOtherName/ instead of http://localhost:8080/MyProject/?

halloleo
  • 9,216
  • 13
  • 64
  • 122

1 Answers1

0

So there are a few options here. You could deploy the application in the root context of the server to get rid of the MyProject in the URL altogether. There are a few ways to do this, but the easiest is to have the .war file from your build be name ROOT.war. This will deploy the application in the server's root context and will get rid of MyProject from the URL. To change the context of the application in your projects URL, you could do so through some configuration of the application (which I don't have enough details to comment on), or through the Tomcat configuration. By deploying the application with the ROOT.war MyProject will be removed from the URL, but you could add <Context path="" docBase="FancyOtherName"></Context> to the $CATALINA_HOME\conf file in the <Host> tag as well as adding to autoDeploy="false" and deployOnStartup="false" to the host tag so it looks something like this <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="false" deployOnStartup="false">. This will stop the application from deploying twice, once in the root context and once at http://localhost:8080/FancyOtherName/, and will only deploy the application at http://localhost:8080/FancyOtherName/. Good Luck!

Scott
  • 63
  • 7
  • Thanks for the details. This gives mw food to poke around... Do you know, how I can instruct Eclipse to deoply to ROOT.war instead of what it normally does? And where is this server config file stored in Eclipse? Is it the one under `[eclipse-workspace]/Servers/server/xml`? – halloleo Oct 09 '20 at 03:40
  • As far as deploying your application to ROOT.war instead of the default name, I would need to know what build tool you are using (Maven, Gradle, etc). I also had another thought that you could instead of renaming your .war ROOT.war, which would deploy it in the root context you could just rename it "FancyOtherName" and it would deploy to http://localhost:8080/FancyOtherName/. Either way, if you could let me know what build tool you are using I could help you further. – Scott Oct 10 '20 at 01:44
  • Thanks for coming back. I don't use any external build tool, I just set up the project in Eclipse, and added a server through the Eclipse wizard, so I have the server property page where I can adjust the server port (and which, I think,represents some xml file). – halloleo Oct 10 '20 at 04:42
  • I'm happy to help I just don't use Eclipse all that much so I'm trying to get a picture of how you're running the application. Do you have Tomcat installed on your machine somewhere that you're using to run the application or are you using a plugin through eclipse to run the Tomcat server? – Scott Oct 10 '20 at 05:18
  • Tomcat is installed on the machine, but it is run from Eclipse: I create the server in Eclipse's _Servers_ view via _Right Click_ -> _New Server_. The project is a _Dynamic Web Project_ and no special plugin is used. – halloleo Oct 14 '20 at 06:48