【问题标题】:Howto get rid of directory prefix in Java webserver url?如何摆脱 Java Web 服务器 url 中的目录前缀?
【发布时间】:2010-09-22 08:58:49
【问题描述】:

我将 Maven 与 Jetty / Tomcat 一起使用。我的 pom.xml 将我的应用程序的 ID 声明为 <artifactId>webapp</artifactId>。因此,我所有的 webapp 源代码都位于src/main/java/webapp。现在,每当我运行任何网络服务器时,我的 URL 都会如下所示:

http://localhost:8080/webapp/index.html

我还没有找到线索告诉我如何摆脱应用程序或目录名称并使 URL 看起来像这样:

http://localhost:8080/index.html

有什么提示吗?

【问题讨论】:

    标签: java maven-2 tomcat jetty


    【解决方案1】:

    有几种方法可以做到这一点:

    • 在 Tomcat 中,将 webapp.war 重命名为 ROOT.war(注意大小写)
    • 在此基础上配置 Apache 并创建一个重写规则以将 root 指向正确的 webapp。
    • 使用 Jetty 的 contextPath

    【讨论】:

      【解决方案2】:

      假设您的意思是使用jetty:runtomcat:run mojos(如果不是,请说明您的意思):

      在 Jetty 中,使用 contextPath 参数:

      <plugin>
          <groupId>org.mortbay.jetty</groupId>
          <artifactId>maven-jetty-plugin</artifactId>
          <!-- version omitted -->
          <configuration>
              <contextPath>/</contextPath>
              <!-- other config -->
          </configuration>
      </plugin>
      

      在 Tomcat 中是 path 参数

      <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>tomcat-maven-plugin</artifactId>
          <!-- Version omitted -->
          <configuration>
              <path>/</path>
              <!-- Other configuration -->
          </configuration>
      </plugin>
      

      【讨论】:

        猜你喜欢
        • 2011-07-06
        • 2017-06-14
        • 1970-01-01
        • 1970-01-01
        • 2020-06-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多