Eclipse WebContent 目录在 tomcat 中的部署
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9657724/
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
Eclipse WebContent directory deployment in tomcat
提问by Cratylus
In Eclipse, the folder structure when I create a Dynamic Web Project is
在 Eclipse 中,我创建动态 Web 项目时的文件夹结构是
[srikanth@hana Sample]$ ls -R
.:
build src WebContent
./build:
classes
./build/classes:
./src:
./WebContent:
index.html META-INF scripts WEB-INF
./WebContent/META-INF:
MANIFEST.MF
./WebContent/scripts:
jquery-1.7.1.js
./WebContent/WEB-INF:
lib web.xml
./WebContent/WEB-INF/lib:
As you can see, there is this WebContent directory, When I copy the directory structure from Eclipse workspace and put in webapps directory of Tomcat, it didn't work. But, if I moved all the directories and files under WebContent directory a level above, it worked fine.
如您所见,有这个WebContent目录,当我从Eclipse工作区复制目录结构并将其放入Tomcat的webapps目录时,它不起作用。但是,如果我将 WebContent 目录下的所有目录和文件移动到上一级,它就可以正常工作。
This is the folder structure in Tomcat's webapps directory under application:
这是Tomcat应用程序下的webapps目录下的文件夹结构:
[srikanth@hana Sample]$ ls -R
.:
build index.html META-INF scripts src WEB-INF
./build:
classes
./build/classes:
./META-INF:
MANIFEST.MF
./scripts:
jquery-1.7.1.js
./src:
./WEB-INF:
lib web.xml
./WEB-INF/lib:
So, now I can just go to http://localhost:8080/Sample
and can go to index.html properly
所以,现在我可以去http://localhost:8080/Sample
并且可以正确地去 index.html
What am I doing wrong? Why didn't it work just copying the application from Eclipse to tomcat webapps directory directly? Why do I have to change the directory structure?
我究竟做错了什么?为什么不直接将应用程序从 Eclipse 复制到 tomcat webapps 目录?为什么我必须改变目录结构?
回答by Ken Lin
I had the same problem, ./WebContent/index.html not appearing in the Eclipse-exported .war. This occurred on my new Eclipse system after I recreated a working project from my old system with Kepler Eclipse to a new system with Luna Eclipse.
我遇到了同样的问题,./WebContent/index.html 没有出现在 Eclipse 导出的 .war 中。在我使用 Kepler Eclipse 从我的旧系统重新创建一个工作项目到使用 Luna Eclipse 的新系统后,这发生在我的新 Eclipse 系统上。
I fixed this by going to Project / Properties / Deployment Assembly. I discovered that the old working system had this rule, while my new non-working systems was missing this rule ...
我通过转到 Project / Properties / Deployment Assembly解决了这个问题。我发现旧的工作系统有这个规则,而我的新非工作系统缺少这个规则......
Source = /WebContent
Deploy Path = /
I corrected this on the new system by Pressing "Add..." and adding the missing rule.
我通过按“添加...”并添加缺少的规则在新系统上更正了这一点。
回答by JB Nizet
Eclipse allows deploying the webapp directly to a server, without needing to copy anything by yourself. It also allows generating a deployable war file when you're ready to deploy to a test or production server.
Eclipse 允许将 web 应用程序直接部署到服务器,而无需您自己复制任何内容。当您准备好部署到测试或生产服务器时,它还允许生成可部署的War文件。
Open the "Servers" view, right-click, and choose to create a new server. Once created, right-click on the server and choose to add your web-app into it. And then Eclipse will deploy your web-app to the server.
打开“服务器”视图,右键单击,然后选择创建新服务器。创建后,右键单击服务器并选择将您的网络应用程序添加到其中。然后 Eclipse 会将您的 Web 应用程序部署到服务器。
You're not supposed to manually copy anything from Eclipse. And if you need or want to do this, then you should probably use some ant script which generates the proper deployment structure. This structure is described in the servlet specification. It should have, under the root directory of the webapp, a WEB-INF directory containing:
您不应该从 Eclipse 手动复制任何内容。如果您需要或想要这样做,那么您可能应该使用一些生成正确部署结构的 ant 脚本。这个结构在 servlet 规范中有描述。它应该在 webapp 的根目录下有一个 WEB-INF 目录,其中包含:
- classes: a directory containing your classes
- lib: a directory containing all the jar files your app depends on
- web.xml the webapp's deployment descriptor
- 类:包含您的类的目录
- lib:包含应用程序依赖的所有 jar 文件的目录
- web.xml webapp的部署描述符
All the other directories and files that are not under WEB-INF can be served by the web container.
不在 WEB-INF 下的所有其他目录和文件都可以由 Web 容器提供服务。
回答by Cratylus
When I copy the directory structure from Eclipse workspace and put in webapps directory of Tomcat, it didn't work. But, if I moved all the directories and files under WebContent directory a level above, it worked fine
当我从 Eclipse 工作区复制目录结构并将其放入 Tomcat 的 webapps 目录时,它不起作用。但是,如果我将 WebContent 目录下的所有目录和文件移动到上一级,它工作正常
Not sure what you mean if I moved all the directories and files under WebContent directory a level above, it worked fine
here and what you mean by saying a level above
.
不确定你if I moved all the directories and files under WebContent directory a level above, it worked fine
在这里的意思以及你所说的意思a level above
。
What you should be doing is not copy anything manually but right-click on the project and select Export as WAR
option.
This will create a file named Project.war
that contains the proper file structure i.e. WEB-INF
etc that you are supposed to put under tomcat's webapps
dir
您应该做的不是手动复制任何内容,而是右键单击项目并选择Export as WAR
选项。
这将创建一个名为的文件Project.war
,其中包含WEB-INF
您应该放在 tomcatwebapps
目录下的正确文件结构即等