将Webapp从Eclipse部署到Tomcat根上下文

时间:2023-01-24 18:54:46

I deploy a .war application from Eclipse by adding the "Dynamic Web Module" facet, then right-clicking on the project and selecting "Run As -> Run on Server".

我通过添加“Dynamic Web Module”方面从Eclipse部署.war应用程序,然后右键单击项目并选择“Run As - > Run on Server”。

This works great, but by default the project is deployed to the /web context of Tomcat, because the project name is web. Is there a way I can deploy from Eclipse to Tomcat without changing the project name to ROOT?

这很好用,但默认情况下,项目部署到Tomcat的/ web上下文,因为项目名称是web。有没有办法从Eclipse部署到Tomcat而无需将项目名称更改为ROOT?

5 个解决方案

#1


78  

You need to go to Server View.. double click on tomcat, this opens a new window (with 2 tabs). Select the one which says Modules, your application would be listed there (with the context path). You can change the context path from /web to anything else from here.

您需要转到服务器视图..双击tomcat,这将打开一个新窗口(带有2个选项卡)。选择一个显示模块的模块,您的应用程序将在那里列出(使用上下文路径)。您可以从此处将上下文路径从/ web更改为其他任何内容。

Alternatively, you can open server.xml look for a tag called context. within this tag you'll find the contextroot as /web.. change it.

或者,您可以打开server.xml查找名为context的标记。在此标记内,您会发现contextroot为/ web ..更改它。

#2


17  

Right click on your project in Eclipse and select Properties->Web Project Settings. Change context name there.

在Eclipse中右键单击您的项目,然后选择Properties-> Web Project Settings。在那里更改上下文名称

Alternatively you can edit it in .settings/org.eclipse.wst.common.component file inside your project

或者,您可以在项目内的.settings / org.eclipse.wst.common.component文件中编辑它

#3


6  

In the Web Project Settings for the project, set the Context root to "/". (Without quotes)

在项目的Web项目设置中,将Context root设置为“/”。 (没有引号)

Just in case you are using apache2 with mod_proxy. In my virtual host definition I have a Location entry for the root context:

以防你使用带有mod_proxy的apache2。在我的虚拟主机定义中,我有一个根上下文的Location条目:

  <Proxy balancer://ajpCluster>
    BalancerMember ajp://localhost:18009 route=s1
    BalancerMember ajp://localhost:28009 route=s2
  </Proxy>

  # A "Location" entry for hosting static content.  Would put mod_expire settings
  # here
  <Location /resources>
    ProxyPass !  #Don't proxy this location
    ExpiresActive on
    ExpiresDefault "access plus 1 seconds"
    ExpiresByType application/javascript "access plus 1 months"
  </Location>

  #...

  # This must be the last "Location" if you are overloading others, otherwise
  # the others won't load as apache uses the first one listed that matches
  <Location />
    ProxyPass balancer://ajpCluster stickysession=JSESSIONID
  </Location>

#4


4  

After you have configured a server in eclipse, you can further configure it and add/remove/tweak any modules (aka contexts/webapps) that you want it to host. You should have a Servers window that list the server (if not: Window > Show View > Servers). Double click on on the server to open the config page. There are 2 tabs, but they are in the bottom left corner. Open Modules, any module you added will be listed. If you want a module to be the default one (so if you type localhost it will server index.jsp, for example) make sure that path says "/". The default value will be what is in your webapps Properties > Web Project Settings, and it usually be the project name. If you set it there, it will not let you leave it blank, so use "/".

在eclipse中配置服务器之后,您可以进一步配置它并添加/删除/调整您希望它托管的任何模块(也就是上下文/ webapps)。您应该有一个列出服务器的服务器窗口(如果不是:窗口>显示视图>服务器)。双击服务器以打开配置页面。有2个选项卡,但它们位于左下角。打开模块,将列出您添加的任何模块。如果你想要一个模块作为默认模块(所以如果你键入localhost它将服务器index.jsp,例如)确保路径说“/”。默认值将是您的webapps属性> Web项目设置中的内容,它通常是项目名称。如果你在那里设置它,它不会让你留空,所以使用“/”。

Make sure you save the config changes for your Server. You may also need to "publish" it to make the changes propagate out to the actual server.

确保保存服务器的配置更改。您可能还需要“发布”它以使更改传播到实际服务器。

A last thing to check is find the server install, open conf/server.xml and look for your contexts. You can change the path there as well. Note that path="" equates to "/", tomcat will make that the ROOT app. Also note that Eclipse will create an empty webapp named ROOT when you first publish it (this will also be in server.xml). It is safe to delete it. Even though your deployed app will have the project name as the webapp name, as long as the path is "", it will treat it as the default ROOT.

要检查的最后一件事是找到服务器安装,打开conf / server.xml并查找您的上下文。您也可以在那里更改路径。请注意,path =“”等同于“/”,tomcat将使其成为ROOT应用程序。另请注意,Eclipse将在您首次发布时创建一个名为ROOT的空Web应用程序(这也将在server.xml中)。删除它是安全的。即使您部署的应用程序将项目名称作为webapp名称,只要路径为“”,它就会将其视为默认ROOT。

#5


1  

Right click the application > Properties > Web Project setings and set the Context root to ROOT (or to empty - I haven't tried it, so try both and let me know which one worked)

右键单击应用程序>属性> Web项目设置并将上下文根设置为ROOT(或清空 - 我还没有尝试过,所以请尝试两者并让我知道哪一个工作)

#1


78  

You need to go to Server View.. double click on tomcat, this opens a new window (with 2 tabs). Select the one which says Modules, your application would be listed there (with the context path). You can change the context path from /web to anything else from here.

您需要转到服务器视图..双击tomcat,这将打开一个新窗口(带有2个选项卡)。选择一个显示模块的模块,您的应用程序将在那里列出(使用上下文路径)。您可以从此处将上下文路径从/ web更改为其他任何内容。

Alternatively, you can open server.xml look for a tag called context. within this tag you'll find the contextroot as /web.. change it.

或者,您可以打开server.xml查找名为context的标记。在此标记内,您会发现contextroot为/ web ..更改它。

#2


17  

Right click on your project in Eclipse and select Properties->Web Project Settings. Change context name there.

在Eclipse中右键单击您的项目,然后选择Properties-> Web Project Settings。在那里更改上下文名称

Alternatively you can edit it in .settings/org.eclipse.wst.common.component file inside your project

或者,您可以在项目内的.settings / org.eclipse.wst.common.component文件中编辑它

#3


6  

In the Web Project Settings for the project, set the Context root to "/". (Without quotes)

在项目的Web项目设置中,将Context root设置为“/”。 (没有引号)

Just in case you are using apache2 with mod_proxy. In my virtual host definition I have a Location entry for the root context:

以防你使用带有mod_proxy的apache2。在我的虚拟主机定义中,我有一个根上下文的Location条目:

  <Proxy balancer://ajpCluster>
    BalancerMember ajp://localhost:18009 route=s1
    BalancerMember ajp://localhost:28009 route=s2
  </Proxy>

  # A "Location" entry for hosting static content.  Would put mod_expire settings
  # here
  <Location /resources>
    ProxyPass !  #Don't proxy this location
    ExpiresActive on
    ExpiresDefault "access plus 1 seconds"
    ExpiresByType application/javascript "access plus 1 months"
  </Location>

  #...

  # This must be the last "Location" if you are overloading others, otherwise
  # the others won't load as apache uses the first one listed that matches
  <Location />
    ProxyPass balancer://ajpCluster stickysession=JSESSIONID
  </Location>

#4


4  

After you have configured a server in eclipse, you can further configure it and add/remove/tweak any modules (aka contexts/webapps) that you want it to host. You should have a Servers window that list the server (if not: Window > Show View > Servers). Double click on on the server to open the config page. There are 2 tabs, but they are in the bottom left corner. Open Modules, any module you added will be listed. If you want a module to be the default one (so if you type localhost it will server index.jsp, for example) make sure that path says "/". The default value will be what is in your webapps Properties > Web Project Settings, and it usually be the project name. If you set it there, it will not let you leave it blank, so use "/".

在eclipse中配置服务器之后,您可以进一步配置它并添加/删除/调整您希望它托管的任何模块(也就是上下文/ webapps)。您应该有一个列出服务器的服务器窗口(如果不是:窗口>显示视图>服务器)。双击服务器以打开配置页面。有2个选项卡,但它们位于左下角。打开模块,将列出您添加的任何模块。如果你想要一个模块作为默认模块(所以如果你键入localhost它将服务器index.jsp,例如)确保路径说“/”。默认值将是您的webapps属性> Web项目设置中的内容,它通常是项目名称。如果你在那里设置它,它不会让你留空,所以使用“/”。

Make sure you save the config changes for your Server. You may also need to "publish" it to make the changes propagate out to the actual server.

确保保存服务器的配置更改。您可能还需要“发布”它以使更改传播到实际服务器。

A last thing to check is find the server install, open conf/server.xml and look for your contexts. You can change the path there as well. Note that path="" equates to "/", tomcat will make that the ROOT app. Also note that Eclipse will create an empty webapp named ROOT when you first publish it (this will also be in server.xml). It is safe to delete it. Even though your deployed app will have the project name as the webapp name, as long as the path is "", it will treat it as the default ROOT.

要检查的最后一件事是找到服务器安装,打开conf / server.xml并查找您的上下文。您也可以在那里更改路径。请注意,path =“”等同于“/”,tomcat将使其成为ROOT应用程序。另请注意,Eclipse将在您首次发布时创建一个名为ROOT的空Web应用程序(这也将在server.xml中)。删除它是安全的。即使您部署的应用程序将项目名称作为webapp名称,只要路径为“”,它就会将其视为默认ROOT。

#5


1  

Right click the application > Properties > Web Project setings and set the Context root to ROOT (or to empty - I haven't tried it, so try both and let me know which one worked)

右键单击应用程序>属性> Web项目设置并将上下文根设置为ROOT(或清空 - 我还没有尝试过,所以请尝试两者并让我知道哪一个工作)