NetBeans - How to import a class from an external library

Greg picture Greg · Aug 8, 2010 · Viewed 16.5k times · Source

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.

Answer

npinti picture npinti · Aug 8, 2010

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.