为什么当我在 Eclipse 中重命名项目时,Tomcat 没有选择新的资源名称?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2174581/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 14:21:55  来源:igfitidea点击:

Why when I rename a project in Eclipse does Tomcat not pick up the new resource name?

eclipseworkspace

提问by Yoni

I did refactor > rename on a project in my workspace, but then when I went under the servers tab and did a right-click > Add and Remove for my Tomcat server in order to modify the resources configured on the server, the resource name for my project is my old project name. I looked everywhere to try and change this, like some sort of Tomcat config file or setting, but I can't find it anywhere. So my project is named one thing, but is configured as a resource on the server under a different name. How do I change this?

我对工作区中的项目进行了重构 > 重命名,但是当我进入服务器选项卡并右键单击 > 添加和删除我的 Tomcat 服务器以修改服务器上配置的资源时,我的项目是我的旧项目名称。我到处寻找尝试更改此设置,例如某种 Tomcat 配置文件或设置,但在任何地方都找不到。所以我的项目被命名为一件事,但被配置为服务器上不同名称的资源。我该如何改变?

回答by Yoni

I believe you are looking for a hidden pref located under your project/.settings/org.eclipse.wst.common.component.

我相信您正在寻找位于your project/.settings/org.eclipse.wst.common.component.

The beginning of the file should look roughly like this:

文件的开头应大致如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
    <wb-module deploy-name="projectB">

So just change the deploy-name. Another thing that I recommend changing is the project's context root, right-click the project -> Properties -> Web Project Settings.

所以只需更改部署名称。我建议更改的另一件事是项目的上下文根,右键单击项目 -> 属性 -> Web 项目设置。

(just to clarify, to the best of my understanding this behavior is a bug in WTP. WTP is responsible for maintaining the hidden pref file under .settings, and it just doesn't update the file when the project is renamed)

(只是为了澄清,据我所知,这种行为是 WTP 中的一个错误。WTP 负责维护 .settings 下的隐藏 pref 文件,并且在项目重命名时它不会更新文件)

回答by Xonatron

Edit your project name here:

在此处编辑您的项目名称:

Eclipse -> Project -> Properties -> Web Project Settings -> Context Root

Eclipse -> Project -> Properties -> Web Project Settings -> Context Root

This is where you want to edit the project name (too), and I believe it will also change the project/.settings/org.eclipse.wst.common.componentfile as mentioned in Yoni's answer above. I would recommend opening it to verify it though. If so, this is the better answer I believe.

这是您想要(也)编辑项目名称的地方,我相信它也会更改project/.settings/org.eclipse.wst.common.component上面 Yoni 的回答中提到的文件。不过,我建议打开它进行验证。如果是这样,我相信这是更好的答案。

EDIT: Anyone who verifies this, please post, and I'll append your verification to my answer.

编辑:任何验证这一点的人,请发帖,我会将您的验证附加到我的答案中。

回答by smat88dd

Unfortunately, changing the Context Root does not update the org.eclipse.wst.common.component-file. So it is really necessary to change the deploy name in the file.

不幸的是,更改上下文根不会更新 org.eclipse.wst.common.component-file。所以在文件中修改deploy name真的很有必要。

回答by Coli

Answering Xonatron's message: changing the context root only changes the URL requested to reach the app. To change the 'resource name' as displayed in Eclipse you have to manually update the file project/.settings/org.eclipse.wst.common.component AND refresh the Eclipse project (F5).

回答 Xonatron 的消息:更改上下文根只会更改请求访问应用程序的 URL。要更改 Eclipse 中显示的“资源名称”,您必须手动更新文件 project/.settings/org.eclipse.wst.common.component 并刷新 Eclipse 项目 (F5)。

回答by Philip Rego

The other answers didn't fix my issue. Deleting and then recreating my tomcat server worked. If you're still having issues run this command from a unix based terminal.

其他答案没有解决我的问题。删除然后重新创建我的 tomcat 服务器工作。如果您仍然遇到问题,请从基于 Unix 的终端运行此命令。

grep -Ril 'yourOldProjectName' 'C:\EclipseWorkspace\yourProjectsDir'

This will look through your entire project for your old project name. The output is the file names of all the files that have your old project name.

这将在您的整个项目中查找您的旧项目名称。输出是具有旧项目名称的所有文件的文件名。

回答by Thibault

Same issue and resolved it by changing manually deploy-namein project/.settings/org.eclipse.wst.common.componentfile and editing Context rootin Eclipse -> Project -> Properties -> Web Project Settings -> Context Root. I have not encountered the issue since I did the trick.

同样的问题,通过改变手动解决它部署名project/.settings/org.eclipse.wst.common.component文件和编辑上下文根Eclipse -> Project -> Properties -> Web Project Settings -> Context Root。自从我做了这个伎俩以来,我还没有遇到过这个问题。

回答by Yash

Added images and some information to @Yoni post.

在@Yoni 帖子中添加了图片和一些信息。



Eclipse tomcat Add Remove still shows old project name. Bug 180741

Eclipse tomcat Add Remove 仍然显示旧的项目名称。 Bug 180741

File: D:\Yashwanth\MyProject.settings\org.eclipse.wst.common.component
Tomcat: MyProject(MyOldProject)

文件:D:\Yashwanth\MyProject.settings\org.eclipse.wst.common.component
雄猫:MyProject(MyOldProject)

<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
    <wb-module deploy-name="MyOldProject">
        <property name="context-root" value="MyProject"/>
        <!-- ... -->
    </wb-module>
</project-modules>

How it looks like when you add a resource from eclipse.

从 eclipse 添加资源时的样子。

enter image description here

在此处输入图片说明

To resolve the issue change from deploy-name="MyOldProject"to deploy-name="MyProject". After changing you will see in Tomcat as MyProject

要解决问题,请从 更改deploy-name="MyOldProject"deploy-name="MyProject"。更改后,您将在 Tomcat 中看到MyProject