为什么有些进口无法解决?

时间:2016-09-25 15:23:20

标签: java eclipse maven lucene

我是java的新手,我尝试使用word net进行传感分析。 当我使用wordnet类时,我在导入时遇到以下失败

import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.lucene.analysis.en.EnglishMinimalStemmer;
import org.apache.stanbol.commons.stanboltools.datafileprovider.DataFileListener;
import org.apache.stanbol.commons.stanboltools.datafileprovider.DataFileTracker;
import org.apache.stanbol.enhancer.engines.sentiment.api.LexicalCategoryClassifier;
import org.apache.stanbol.enhancer.engines.sentiment.api.SentimentClassifier;
import org.apache.stanbol.enhancer.engines.sentiment.util.WordSentimentDictionary;
import org.apache.stanbol.enhancer.nlp.pos.LexicalCategory;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.ComponentContext;

无法解决上述所有导入,例如org.apache.felixorg.apache.luceneorg.apache.stanbolorg.osgi

enter image description here

2 个答案:

答案 0 :(得分:2)

这是因为您的编译器无法找到解析这些导入所需的必要包和/或库。这些包必须包含在类路径中。例如,有关

的所有错误
org.apache.felix.scr.annotations.x
https://mvnrepository.com/artifact/org.apache.felix/org.apache.felix.scr.annotations/1.11.0

下载最新的.jar后,可以解决

按照以下步骤将jar文件包含在类路径中。       -

  • 将所需的jar文件从下载目录拖到src eclipse中项目的目录
  • 右键单击jar文件,选择 Build Path ,然后选择Add To Build Path选项。
  • 将出现一个对话框,要求您链接jar文件中的所有文件,只需坚持默认值并点击OK。
  • 您现在已经完成,所有关于导入的错误都将得到解决。

答案 1 :(得分:1)

这些包需要在编译器的类路径中。

另一种说法:编译器需要能够知道在哪里找到这些文件。这带来了一些限制:

  • 这些文件实际上需要存在于您的硬盘中(无论是手动添加,还是由依赖管理器自动添加)
  • 应将它们组织在与包名称部分匹配的文件夹中
  • 它们所在的文件夹必须位于类路径中,可以使用“classpath”编译器选项指定,也可以在IDE的选项中指定
相关问题