Eclipse Dynamic Web Project 如何组织文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28743150/
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 Dynamic Web Project how to organize files?
提问by Hoodlum
So I'm learning web application development and I'm a bit confused about how to organize my files in the template provided by eclipse for Dynamic Web Application.
所以我正在学习 Web 应用程序开发,我对如何在 Eclipse 为动态 Web 应用程序提供的模板中组织我的文件有点困惑。
Should I place my HTML pages in WebContent? Where do I put the JSP and servlet source files? What convention is globally followed?
我应该将 HTML 页面放在 WebContent 中吗?我在哪里放置 JSP 和 servlet 源文件?全球遵循什么惯例?
This is the structure of the template provided by eclipse
这是eclipse提供的模板结构
- Deployment Descriptor
- JavaScript Resources
- WebContent
- ECMAScript Built-In Library
- ECMA 3 Browser Support Library
- src
- JRE System Library
- Apache Tomcat v8
- Web App Libraries
- EAR libraries
- build
- WebContent
- META-INF
- WEB-INF
- lib
- 部署描述符
- JavaScript 资源
- 网页内容
- ECMAScript 内置库
- ECMA 3 浏览器支持库
- 源文件
- JRE 系统库
- Apache Tomcat v8
- 网络应用程序库
- EAR 库
- 建造
- 网页内容
- 元信息
- 网络信息
- 库
回答by Pete
Place HTML and JSP pages in the WebContent
directory.
将 HTML 和 JSP 页面放在该WebContent
目录中。
The Eclipse help page referenced by android-weblineindiastates that WebContent is:
android-weblineindia 引用的 Eclipse 帮助页面指出 WebContent 是:
The mandatory location of all Web resources, including HTML, JSP, graphic files, and so on. If the files are not placed in this directory (or in a subdirectory structure under this directory), the files will not be available when the application is executed on a server. The Web content folder represents the contents of the WAR file that will be deployed to the server. Any files not under the Web content folder are considered development-time resources (for example, .java files, .sql files, and .mif files), and are not deployed when the project is unit tested or published.
所有 Web 资源的强制位置,包括 HTML、JSP、图形文件等。如果文件未放置在此目录中(或此目录下的子目录结构中),则在服务器上执行应用程序时文件将不可用。Web 内容文件夹表示将部署到服务器的 WAR 文件的内容。任何不在 Web 内容文件夹下的文件都被视为开发时资源(例如,.java 文件、.sql 文件和 .mif 文件),并且不会在项目进行单元测试或发布时部署。
so CSS files and JS files needed by the browser should also be placed here.
所以浏览器需要的CSS文件和JS文件也应该放在这里。
Place java source files (so including servlet sources) in the src
directory. The same help page states this for the source directory (although it suggests it is called JavaSource which looks like an error in the documentation):
将 java 源文件(包括 servlet 源)放在src
目录中。相同的帮助页面说明了源目录的这一点(尽管它表明它被称为 JavaSource,这在文档中看起来像一个错误):
Contains the project's Java source code for classes, beans, and servlets. When these resources are added to a Web project, they are automatically compiled and the generated files are added to the WEB-INF/classes directory. The contents of the source directory are not packaged in WAR files unless an option is specified when a WAR file is created.
包含项目的类、bean 和 servlet 的 Java 源代码。当这些资源添加到Web项目中时,它们会被自动编译并将生成的文件添加到WEB-INF/classes目录中。除非在创建 WAR 文件时指定了一个选项,否则源目录的内容不会打包在 WAR 文件中。
If you look at project Properties -> Deployment Assembly
you should see that files compiled from src
are deployed to WEB-INF/classes
and files in WebContent
are deployed to the root of the WAR file
如果你看一下项目Properties -> Deployment Assembly
,你应该看到,从编译后的文件src
被部署到WEB-INF/classes
并在文件中WebContent
被部署到WAR文件的根