3

I have a Java project in Netbeans and I want to use some classes from Weka within my project.

I added the file C:\Program Files\Weka-3-7\weka-src.jar into my Libraries following the instructions here (project, properties, libraries ..)

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.

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.

Greg
  • 45,306
  • 89
  • 231
  • 297

2 Answers2

4

I have downloaded Weka from here. I have added the JAR file you mentioned and I have also added 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.

npinti
  • 51,780
  • 5
  • 72
  • 96
  • I do see it under that libraries folder. I updated my question to describe what I see. – Greg Aug 08 '10 at 19:44
  • Sorry, my bad, you have to also add weka.jar – npinti Aug 08 '10 at 19:46
  • Hmm I'll try that. Out of curiousity, why do I need both? – Greg Aug 08 '10 at 19:57
  • If I remeber correctly, the first import you are using lies within weka.jar, whilst the second one, even though it does not seem to exist in the weka-src.jar file, has a very similar stucture to the items found in weka-src.jar – npinti Aug 08 '10 at 20:05
0

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.

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"