java NetBeans - 如何从外部库导入类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3435698/
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
NetBeans - How to import a class from an external library
提问by Greg
I have a Java project in Netbeans and I want to use some classes from Wekawithin my project.
我在 Netbeans 中有一个 Java 项目,我想在我的项目中使用Weka中的一些类。
I added the file C:\Program Files\Weka-3-7\weka-src.jar into my Libraries following the instructions here(project, properties, libraries ..)
我按照此处的说明将文件 C:\Program Files\Weka-3-7\weka-src.jar 添加到我的库中(项目、属性、库 ..)
So how do I now import the classes I want?
那么我现在如何导入我想要的类?
I tried importing like this:
我尝试像这样导入:
import weka.core.converters.ConverterUtils.DataSource;
And for kicks, I also tried this which didn't work either:
对于踢球,我也试过这个也不起作用:
import src.main.java.weka.core.converters.ConverterUtils.DataSource;
NetBeans says "package does not exist" for both.
NetBeans 对两者都说“包不存在”。
Have I linked the libraries incorrectly? Do I need to phrase the import differently?
我是否错误地链接了库?我需要用不同的方式表达导入吗?
Much thanks for any insight into this you can provide.
非常感谢您对此提供的任何见解。
Update:
更新:
In my Libraries folder of my projects tab I see:
在我的项目选项卡的库文件夹中,我看到:
weka-src.jar and under that I see: , META-INF, lib, src.main.java.weka.associations, and lots of other things from weka.
weka-src.jar 和在它下面我看到:、META-INF、lib、src.main.java.weka.associations,以及来自 weka 的许多其他东西。
回答by npinti
I have downloaded Weka from here. I have added the JAR file you mentioned and I have also added weka-src.jar.
我已经从这里下载了 Weka 。我已经添加了你提到的 JAR 文件,我还添加了 weka-src.jar。
The problem is that although I have no problems with your first import:
问题是,虽然我对你的第一次导入没有问题:
import weka.core.converters.ConverterUtils.DataSource;
I can't see this package anywhere:
我在任何地方都看不到这个包:
import src.main.java.weka.core.converters.ConverterUtils.DataSource;
To see if you have successfully imported a .jar file or a library, click on the "Projects" button on the left margin, find the Project you have added the resource to and expand the view (by pressing the + sign). You should have an item named "Libraries". If you expand that, you should be able to see the files you have added.
要查看您是否已成功导入 .jar 文件或库,请单击左边距上的“项目”按钮,找到您已添加资源的项目并展开视图(按 + 号)。您应该有一个名为“库”的项目。如果您展开它,您应该能够看到您添加的文件。
回答by Jordi García
I was looking for how to install Weka Jar file too, and I read this tutorial and I realize that the jar file is actually on you Weka installer, and then you just need to import the jar file as same as any other library. Take a chance to look this tutorial, it is pretty cool.
我也在寻找如何安装 Weka Jar 文件,我阅读了本教程,我意识到 jar 文件实际上在你的 Weka 安装程序上,然后你只需要像导入任何其他库一样导入 jar 文件。有机会看看这个教程,它很酷。
http://www.cs.umb.edu/~ding/history/480_697_spring_2013/homework/WekaJavaAPITutorial.pdf
http://www.cs.umb.edu/~ding/history/480_697_spring_2013/homework/WekaJavaAPITutorial.pdf
"Logic will take you from point A to point B, imagination will take you everywhere"
“逻辑会带你从 A 点到 B 点,想象力会带你到任何地方”

