[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 408
  • Last Modified:

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 SenBg.com.cole.Sensor{

The name of the Jar file is SenBg.jar.The error reads "package SenBg.com.cole 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.
0
Nailhead
Asked:
Nailhead
  • 4
  • 2
  • 2
1 Solution
 
CEHJCommented:
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
0
 
CEHJCommented:
And i'd take a guess that should be

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

but please list the jar
0
 
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 {

}
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
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!
0
 
CEHJCommented:
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
0
 
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.
0
 
CEHJCommented:
>>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.
0
 
zzynxSoftware engineerCommented:
Thanks for accepting
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now