Solved

Adding a Jar file to a project in Netbeans 3.6

Posted on 2004-10-21
365 Views
Last Modified: 2012-05-05
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
Question by:Nailhead
    8 Comments
     
    LVL 86

    Expert Comment

    by:CEHJ
    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
     
    LVL 86

    Expert Comment

    by:CEHJ
    And i'd take a guess that should be

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

    but please list the jar
    0
     
    LVL 37

    Accepted Solution

    by:
    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
     

    Author Comment

    by:Nailhead
    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
     
    LVL 86

    Expert Comment

    by:CEHJ
    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
     

    Author Comment

    by:Nailhead
    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
     
    LVL 86

    Expert Comment

    by:CEHJ
    >>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
     
    LVL 37

    Expert Comment

    by:zzynx
    Thanks for accepting
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    1. Package the applet into a JAR file. The applet must be in a JAR file before a certificate can be attached to it. Use the jar JDK utility. If the applet was previously referenced with the help of a codebase attribute in  tag, replace the codebase …
    Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
    Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

    913 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now