简体   繁体   English

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

[英]why some imports cannot be resolved?

I'm new to java , i tried to use word net for senitment analysis . 我是Java的新手,我曾尝试使用word net进行分析。 when i used class of wordnet , i got the following failure in importing 当我使用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;

all the above imports cannot be resolved like org.apache.felix , org.apache.lucene , org.apache.stanbol , org.osgi 上述所有导入都无法解析,例如org.apache.felixorg.apache.luceneorg.apache.stanbolorg.osgi

在此处输入图片说明

This is because your compiler is not able to find the necessary packages and or libraries that are needed to resolve these imports. 这是因为您的编译器无法找到解决这些导入所需的必要包和/或库。 These packages must be included in your class path. 这些软件包必须包含在您的类路径中。 For example all of the errors regarding 例如,所有有关的错误

org.apache.felix.scr.annotations.x

can be resolved after downloading the latest .jar from https://mvnrepository.com/artifact/org.apache.felix/org.apache.felix.scr.annotations/1.11.0 https://mvnrepository.com/artifact/org.apache.felix/org.apache.felix.scr.annotations/1.11.0下载最新的.jar后可以解决

Follow these steps to include jar files in your class path. 请按照以下步骤在您的类路径中包含jar文件。 - --

  • Drag the required jar file from your download directory to the src directory of your project in eclipse 将所需的jar文件从下载目录拖到eclipse中项目的src目录中
  • Right click on the jar file, Select Build Path and then select Add To Build Path option. 右键单击jar文件,选择“ 构建路径” ,然后选择“添加到构建路径”选项。
  • A dialogue box will appear asking you to link all files in the jar file, just stick with the defaults and hit OK. 将出现一个对话框,要求您链接jar文件中的所有文件,只需坚持默认设置,然后单击OK。
  • You are done now, all your errors regarding imports will be resolved. 现在您已完成,有关导入的所有错误将得到解决。

These packages need to be within the compiler's class path. 这些软件包必须位于编译器的类路径中。

Another way to say it : the compiler needs to be able to know where to find these files. 换句话说,编译器需要知道在哪里可以找到这些文件。 This imposes several constraints: 这施加了一些约束:

  • these files need to actually exist in your hard drive (whether added manually, or automatically by a dependency manager) 这些文件实际上需要存在于您的硬盘驱动器中(无论是手动添加还是由依赖项管理器自动添加)
  • they should be organized in folders that match the parts of the package name 它们应该组织在与软件包名称各部分匹配的文件夹中
  • the folder where they are must be within the class path, which can be specified with the 'classpath' compiler option, or in your IDE's options 它们所在的文件夹必须在类路径中,可以使用“ classpath”编译器选项或在IDE的选项中指定

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

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