Adding a Jar file to a project in Netbeans 3.6

How do I add a Jar file to a project in Netbeans 3.6? I've tried mounting the Jar file in the Filesystem. It appears in the Filesystem window where I can browse all of the different classes. Then I get an error on this line:

 public class MySensor extends{

The name of the Jar file is SenBg.jar.The error reads "package does not exist".

I've tried adding this line just above it:
 import SenBG.*;

That doesn't work either, I get the same error. I've even tried copying the Jar file to the \lib\ext directory with no luck. However I'd rather find a solution that doesn't involve any file copying.
Who is Participating?
zzynxSoftware engineerCommented:
You add a jar file to the project by mounting it. That's correct.
But the classes inside that jar have a path too.   (You can open a jar with WinZip to have a look)
If you want to use the class TheClass and it is in the path x/Y/z in the jar file

then in your code you have to

            import x.Y.z.*;

that way you can use the class:

public MyClass extends TheClass {

That should be more like

import com.cole.SenBg.*;

i'd guess.

Please list the jar in its directory by doing the following

jar tvf SenBg.jar

at the command line
And i'd take a guess that should be

public class MySensor extends com.cole.SenBg.Sensor {}

but please list the jar
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

NailheadAuthor Commented:
CEHJ, I tried your suggestions, without any luck. I listed the jar on the command line and here is one line from the class that I want to implement:

   646 Fri Oct 01 14:08:28 CDT 2004 com/cole/sensor/Sensor.class

I also opened it in WinZip and saw that the path is the same as the listing. Next I changed the line using zzynx's x/Y/z rule and it worked!

import com.cole.sensor.*;

That was the answer, thanks all!
I fail to see how (apart from mentioning WinZip) the accepted answer differs from the ones i already gave. If you'd posted that path as i asked you too, we could have saved a lot of time
NailheadAuthor Commented:
CEHJ, The one most important difference in the accepted answer is that the Jar file is not cited in the code anywhere.

In your example, you cite the name of the Jar (SenBg):
import com.cole.SenBg.*;

The exact path of the Jar file that I'm implementing isn't relevant. What I needed to know was the general syntax, and that is what zzynx supplied.

I do appreciate your help.
>>The exact path of the Jar file that I'm implementing isn't relevant

It's the path *inside* the jar that is important, indeed the only thing that's important, which is why i asked you to list it.
zzynxSoftware engineerCommented:
Thanks for accepting
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.