了解 Eclipse 中导入的 WAR 及其文件夹结构
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/349978/
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
Understanding imported WAR in Eclipse and its folder structure
提问by Vidar
I have just imported a WAR file from an external site, which is basically a servlet into Eclipse IDE (the project runs on Apache-Tomcat).
我刚刚从外部站点导入了一个 WAR 文件,它基本上是一个 servlet 到 Eclipse IDE(该项目在 Apache-Tomcat 上运行)。
When I import it it has a folder called Web App Libraries. So here are a few of my newbie questions:
当我导入它时,它有一个名为Web App Libraries的文件夹。所以这里是我的一些新手问题:
I am unsure about what the exact purpose is of this folder is? What does it do, why would you choose to have it in your project?
I see that it has a folder called Improted Classesand foobar.class files inside it - why?
(These seemed to be mirrored in Web Contentfolder - although here you can modify the code as they are foobar.java.)There are references to foobar.jar files too - these are also mirrored in WEB-INF/libfolder too - why?
我不确定这个文件夹的确切用途是什么?它有什么作用,为什么你会选择在你的项目中使用它?
我看到它里面有一个名为Improted Classes和 foobar.class 文件的文件夹- 为什么?
(这些似乎反映在Web Content文件夹中 - 尽管在这里您可以修改代码,因为它们是 foobar.java。)也有对 foobar.jar 文件的引用 - 这些也反映在WEB-INF/lib文件夹中 - 为什么?
I know these are basic type questions but I'm just getting to grips with Java and website dev, so apologies if they sound a bit dumb! - BTW if anyone knows any good online resource to understand more about project file structures like this, then let me know. I just need to get to grips with this stuff asap - as the project deadline is fairly soon.
我知道这些是基本类型的问题,但我刚刚开始掌握 Java 和网站开发,所以如果它们听起来有点愚蠢,我深表歉意!- 顺便说一句,如果有人知道任何好的在线资源以了解有关此类项目文件结构的更多信息,请告诉我。我只需要尽快掌握这些东西 - 因为项目截止日期很快。
Cheers.
干杯。
Here's a screenshot just to help you visualise:
这是一个屏幕截图,只是为了帮助您可视化:
回答by Powerlord
Web App Libraries isn't a real directory, but rather a listing of what Eclipse thinks are this project's libraries.
Web App Libraries 不是真正的目录,而是 Eclipse 认为是该项目的库的列表。
Generally, this consists of all the jar files in WebContent/WEB-INF/lib/
通常,这包括 WebContent/WEB-INF/lib/ 中的所有 jar 文件
Sometimes, Eclipse no longer lists them in their real directory in Eclipse's Package Explorer... but they're still there if you look with another program.
有时,Eclipse 不再将它们列在 Eclipse 包资源管理器的真实目录中……但是如果您使用另一个程序查看它们,它们仍然存在。
回答by david a.
I assume this is a screenshot from the 'Project Explorer' view. It does not display exact folders and files structure, is adds a few candy constructed from project's metadata.
我假设这是来自“项目资源管理器”视图的屏幕截图。它不显示确切的文件夹和文件结构,只是添加了一些根据项目元数据构造的糖果。
- To see real structure of your project, try switching to the 'Navigator' view.
- During a WAR file import, Eclipse basically does two things:
- Creates a new web project and copies WAR's content to 'WebContent' subfolder of the new project.
- Based on the WAR, it constructs project's metadata (.project and .classpath files).
- The 'Web App Libraries' section displays list of jar files that the WAR contained (in WEB-INF/lib
- 'Imported classes' (which I also see for a first time) seem to contain classes found in the imported WAR (WEB-INF/classes), for which Eclipse was not able to find any corresponding source files. To fix this, create a new Java source folder in the project and move the classes you now have in 'firstResource' folder to it.
- 要查看项目的真实结构,请尝试切换到“导航器”视图。
- 在 WAR 文件导入期间,Eclipse 基本上会做两件事:
- 创建一个新的 Web 项目并将 WAR 的内容复制到新项目的“WebContent”子文件夹中。
- 它基于 WAR 构建项目的元数据(.project 和 .classpath 文件)。
- “Web 应用程序库”部分显示 WAR 包含的 jar 文件列表(在 WEB-INF/lib
- “导入的类”(我也是第一次看到)似乎包含在导入的 WAR (WEB-INF/classes) 中找到的类,Eclipse 无法找到任何相应的源文件。要解决此问题,请在项目中创建一个新的 Java 源文件夹,并将您现在在“firstResource”文件夹中的类移动到该文件夹中。
回答by JeeBee
In Eclipse, if you are using the Java Web Development view, you'll have configured:
在 Eclipse 中,如果您使用 Java Web Development 视图,您将配置:
- A Tomcat Server runtime that provides the servlet libraries
- A Java Runtime
- Other required libraries
- 提供 servlet 库的 Tomcat 服务器运行时
- Java 运行时
- 其他需要的库
The Web App Libraries that are in the project duplicate the first setting, so that you don't need a local Tomcat installed on the development box.
项目中的 Web App Libraries 复制了第一个设置,这样您就不需要在开发盒上安装本地 Tomcat。
The rest sounds messy to me.
其余的对我来说听起来很混乱。
You have your src / JavaSource folder with the raw Java files in it. They shouldn't be in Web Content - that's for your HTML, images, JSPs, etc.
您有 src / JavaSource 文件夹,其中包含原始 Java 文件。它们不应该出现在 Web 内容中 - 那是用于您的 HTML、图像、JSP 等。
So a typical project setup:
所以一个典型的项目设置:
Project Name/
JavaSource/ or src/ // holds all the Java Source Files, Servlets, Struts Actions
WebContent/ // Nice root folder to hold web content files
content files and folders
WEB-INF/ // Web App Config folder
lib/ // Libraries (but not tomcat ones)
web.xml
classes/ // Where your compiled Java goes, and configs (log4j.properties)
Some people put the JSP inside WEB-INF too, as it isn't required to be accessible in the JSP file state, only in the compiled state that Tomcat does itself.
有些人也把 JSP 放在 WEB-INF 中,因为它不需要在 JSP 文件状态下访问,只有在 Tomcat 自己做的编译状态下才能访问。
回答by Loki
Its simple, eclipse provides multiple view to your project structure. The view you are looking at is definitely the Package Explorer view. In that view, everything that has a special icon in front is a helper item which is there to help you out by simplifying access to certain stuff like external libraries (which are provided by software on your computer or eclipse itself or other project).
其简单的 eclipse 为您的项目结构提供了多种视图。您正在查看的视图绝对是 Package Explorer 视图。在那个视图中,前面有一个特殊图标的所有东西都是一个帮助项,它可以通过简化对某些东西的访问来帮助你,比如外部库(由你的计算机上的软件或 eclipse 本身或其他项目提供)。
In eclipse, go to menu->window->show view->navigator The Navigator view will tell you the real folder structure of your project.
在 eclipse 中,转到 menu->window->show view->navigator Navigator 视图将告诉您项目的真实文件夹结构。