Results 1 to 8 of 8
  1. #1
    emosms is offline Member
    Join Date
    May 2010
    Posts
    29
    Rep Power
    0

    Default netbeans can't find class in .jar file

    HI,
    I've imported a .jar file containing some classes.
    (Libraries/r.click/Add Jar/Folder)
    But when I use a class from .jar file, netbeans can't find it.

    Do I have to every time drag the class java file into my project package?
    Actually it runs from command line when I add a classpath to the .jar file, but in netbeans it won't, have to include the classes I need into the project.

  2. #2
    Solarsonic is offline Senior Member
    Join Date
    Mar 2011
    Posts
    261
    Rep Power
    4

    Default

    Importing your library into Netbeans isn't enough, you have to add it to your project as well.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    You've got to change your project settings in netbeans so it will include the Jar file(s) on the build path. I know how to do this in Eclipse but not NetBeans, but the help files will tell you how.

  4. #4
    emosms is offline Member
    Join Date
    May 2010
    Posts
    29
    Rep Power
    0

    Default

    Yes, but I didn't import a library. I imported a jar flie under:
    Navigator/Projects/MyProjectName/Libraries
    Imported it with a right click on Libraries/Add Jar/Folder
    Isn't it imported into the project now?

    Then I also have to manually find the classes I need from the jar file and copy the source into:
    Navigator/Projects/MyProjectName/Source Package/package
    - where my source files are

    So it pretty much didn't import anything, I can just drag/copyPaste what I need from one folder to another folder in my project (really advanced :D)

    P.S. I will post that into netbeans forum as well, thx

    Adding one more line - I DO see the jar file under:
    Project/r.click-properties/Libraries/Compile-time Libraries
    So I really see no point what the problem is.
    Last edited by emosms; 05-08-2011 at 06:33 PM.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  6. #6
    emosms is offline Member
    Join Date
    May 2010
    Posts
    29
    Rep Power
    0

    Default

    dont know where is the build path

  7. #7
    emosms is offline Member
    Join Date
    May 2010
    Posts
    29
    Rep Power
    0

    Default

    Oops
    Java puts the source into "Packages"
    Seems like when there is no package defined - it puts them into <default package>
    So, the .jar file has the class and source files into a "default package"
    The netbeans project puts the source into a package with the same name as the project name.
    Now I moved the source file out of the "package" and it automatically wrapped them into some "entity" called <default package> // or no package
    And now the source files see the classes in the jar file :)

    Maybe have to mess into the project xml files and alter the path to the library when I need to work with package different than the <default>

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default

    You're messing up, big time. Depending on what downloaded jar(s) you're using, it may even be a violation of the license agreement.

    Go through the NetBeans help and find how to correctly use an external jar, without having to gut it and spread entrails all over the place.

    db

Similar Threads

  1. .jar file cant find main class
    By eLancaster in forum New To Java
    Replies: 3
    Last Post: 02-10-2011, 12:17 PM
  2. cannot find the class file when running the java command
    By kulangotski in forum New To Java
    Replies: 4
    Last Post: 01-18-2011, 12:34 PM
  3. Jar file could not find the main class
    By Collinryans in forum New To Java
    Replies: 3
    Last Post: 06-23-2010, 05:18 AM
  4. how to find class name when have only jar file?
    By matvey in forum Java Applets
    Replies: 9
    Last Post: 10-13-2009, 02:49 PM
  5. Replies: 0
    Last Post: 05-13-2008, 07:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •