简体   繁体   中英

Can I debug WebApps in Tomcat and Eclipse with blank project name?

I'm developing multiple java-ee web apps in Eclipse kepler & tomcat7 and now everything goes well. I get a specific app with http://localhost:8080/appname .

But can I do some settings to make this project with a blank name so that I can visit it by http://localhost:8080/

Tomcat 6: How to change the ROOT application may not work for the server integration way in Eclipse.

PS: Running on Windows XP with eclipse-jee-kepler-R-win32 and tomcat7

From experience, I would say that it cannot be done.

Since we cannot hide the URL.

Instead you can do,

  • Redirect the URL to application server via web server(Apache WebServer) so when you hit http://localhost:8080/ it will automatically redirect to the mapped URL say, http://localhost:8080/appname

    Cf : How to rewrite URL in Tomcat 6 and Is there a url rewriting engine for Tomcat/Java?

  • You can develop your application as a single page application and replace your content by updating div and span using AJAX . If you give http://localhost:8080/appname without changing or redirecting the URL we can do our tasks.

Creating (or renaming) a project called "ROOT" allowed me to do this within Eclipse.

When you initially "Run on Server" it will load the app using the long-form URL:

http://localhost:8080/ROOT

But if you navigate to:

http://localhost:8080/

You'll see it hits the same page.

One caveat is that in the Tomcat settings page in Eclipse, you'll need to ensure the Server Location is set to "Use workspace metadata". I initially had it set to "Use Tomcat installation" and calling the default http://localhost:8080/ URL would just load Tomcat's default page (presumably because a ROOT application already exists / takes precedence).

Update

I've found you can achieve the same result without changing your project name. Simply edit your Eclipse project's .settings/org.eclipse.wst.common.component file and change the context-root property to "ROOT" like so:

<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
    <wb-module deploy-name="YourProjectName">
        <wb-resource deploy-path="/" source-path="/WebContent" tag="defaultRootSource"/>
        <wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>
        <property name="java-output-path" value="/YourProjectName/build/classes"/>
        <property name="context-root" value="ROOT"/>
    </wb-module>
</project-modules>

Where "YourProjectName" is the name of your project, obviously. :)

Second Update

According to this answer on a related question you can actually change the content-root from the GUI in Eclipse but going to "Web Project Settings" in your project settings.

well there are quite easy ways to do this:

  1. double click the Server Name (eg Tomcat 7) in the Servers view;
  2. go the Modules tab;
  3. select the appname and click edit, then leave the path to blank

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM