Eclipse WTP:项目中定义的类的 JSP 文件中出现“无法解析导入 ___”错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1540857/
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 WTP: "The import ___ cannot be resolved for" error in a JSP file for a class defined in project
提问by Sajee
A Visual Studio user struggling w/ Eclipse...
一个 Visual Studio 用户在使用 Eclipse 时苦苦挣扎......
I imported a set of servlets/JSPs into a project in Oracle Workshop for Weblogic. /page.jsp has the following import statement:
我将一组 servlet/JSP 导入到 Oracle Workshop for Weblogic 中的一个项目中。/page.jsp 有以下导入语句:
import="com.foo.bar.*"
Eclipse is displaying an error:
Eclipse 显示错误:
The import com cannot be resolved.
导入 com 无法解析。
The class that implements the above import is in /WEB-INF/src
but I don't know how to build the class in Eclipse to resolve that error. I assumed Eclipse would automagically build the .java
file and place the output in /WEB-INF/classes
, but it's not doing that.
实现上述导入的类在,/WEB-INF/src
但我不知道如何在 Eclipse 中构建该类来解决该错误。我假设 Eclipse 会自动构建.java
文件并将输出放在/WEB-INF/classes
.
It could be that I haven't structured my project directories correctly so perhaps that's why Eclipse isn't building my source. Any suggestions? How can I get this to work?
可能是我没有正确构建我的项目目录,所以也许这就是 Eclipse 没有构建我的源代码的原因。有什么建议?我怎样才能让它工作?
回答by ChssPly76
First of all, /WEB-INF/src
is a rather strange place to keep your java sources; you may want to move them out of /WEB-INF
(into /src
in project root, for example)
首先,/WEB-INF/src
是一个相当奇怪的地方来保存你的java源代码;您可能希望将它们移出/WEB-INF
(/src
例如移入项目根目录)
Either way, you need to tell Eclipse where your sources are and where you want classes built to. It's done in project properties dialog:
无论哪种方式,您都需要告诉 Eclipse 您的源在哪里以及您希望将类构建到哪里。它在项目属性对话框中完成:
- Right-click on your project in Eclipse, select Properties
- Click on Java Build path on the left
- Click source tab on the right
- Click Add Folder button and add your source folder (
/WEB-INF/src
or wherever you moved it to) - Ensure Allow output folders for source foldersis checked below
- Under newly added source path select output folder and point it to
/WEB-INF/classes
or other location of your choice.
- 在 Eclipse 中右键单击您的项目,选择 Properties
- 单击左侧的 Java Build 路径
- 单击右侧的源选项卡
- 单击添加文件夹按钮并添加您的源文件夹(
/WEB-INF/src
或您将其移动到的任何位置) - 确保在下面选中允许源文件夹的输出文件夹
- 在新添加的源路径下选择输出文件夹并将其指向
/WEB-INF/classes
或您选择的其他位置。