简体   繁体   English

Eclipse WTP:项目中定义的类的JSP文件中的“无法解析导入___”错误

[英]Eclipse WTP: “The import ___ cannot be resolved for” error in a JSP file for a class defined in project

A Visual Studio user struggling w/ Eclipse... 一个正在使用Eclipse奋斗的Visual Studio用户...

I imported a set of servlets/JSPs into a project in Oracle Workshop for Weblogic. 我将一组servlet / JSP导入到Oracle Workshop for Weblogic的项目中。 /page.jsp has the following import statement: /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. 实现上述导入的类位于/WEB-INF/src但是我不知道如何在Eclipse中构建该类来解决该错误。 I assumed Eclipse would automagically build the .java file and place the output in /WEB-INF/classes , but it's not doing that. 我以为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. 可能是因为我没有正确构建项目目录,所以也许这就是Eclipse无法构建源代码的原因。 Any suggestions? 有什么建议么? How can I get this to work? 我该如何工作?

First of all, /WEB-INF/src is a rather strange place to keep your java sources; 首先, /WEB-INF/src是保存Java源代码的一个非常奇怪的地方; you may want to move them out of /WEB-INF (into /src in project root, for example) 您可能需要将它们从/WEB-INF移出(例如,移至项目根目录中的/src中)

Either way, you need to tell Eclipse where your sources are and where you want classes built to. 无论哪种方式,您都需要告诉Eclipse您的源代码在哪里以及要在其中构建类的地方。 It's done in project properties dialog: 在项目属性对话框中完成:

  1. Right-click on your project in Eclipse, select Properties 在Eclipse中右键单击您的项目,选择Properties
  2. Click on Java Build path on the left 单击左侧的Java Build路径
  3. Click source tab on the right 单击右侧的源选项卡
  4. Click Add Folder button and add your source folder ( /WEB-INF/src or wherever you moved it to) 单击添加文件夹按钮,然后添加您的源文件夹( /WEB-INF/src或将其移动到的位置)
  5. Ensure Allow output folders for source folders is checked below 确保在下面选中允许源文件夹的输出文件夹
  6. Under newly added source path select output folder and point it to /WEB-INF/classes or other location of your choice. 在新添加的源路径下,选择输出文件夹,并将其指向/WEB-INF/classes或您选择的其他位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM