Results 1 to 5 of 5
  1. #1
    Umi
    Umi is offline Member
    Join Date
    Sep 2009
    Posts
    10
    Rep Power
    0

    Default Import your own package

    When I import a Java package, I can for example write:
    import javax.swing.*;
    The question is, how would I proceed if I want to import my own package?

    I'm using netbeans, and I tried to add a new Library, in tools->libraries, but it doesn't recognize the package it seems.

    I tried to copy my jar package to "D:\Program Files (x86)\Java\jdk1.6.0_17\jre\lib" but that didn't seem to help either.

  2. #2
    m00nchile is offline Senior Member
    Join Date
    Feb 2010
    Location
    Ljubljana, Slovenia
    Posts
    470
    Rep Power
    5

  3. #3
    kivohs is offline Member
    Join Date
    Feb 2010
    Posts
    1
    Rep Power
    0

    Default

    Hi Umi,
    I dont think there is any need to create a library or anything.
    In netbeans there is an option to create a package . Right-click on src folder and create one using that and then you can import your package just like you import java packages (java(x). xyx.* or something like that)

  4. #4
    Umi
    Umi is offline Member
    Join Date
    Sep 2009
    Posts
    10
    Rep Power
    0

    Default

    Quote Originally Posted by m00nchile View Post
    I did like he said and set a new Environment Variable CLASSPATH as "E:\NetBeansProjects\Java\Packages". And then I put my package "mypackage" there, but when I try to write: "import mypackage.", nothing pops up, and trying to compile the file gives me error about the package doesn't exist.


    Quote Originally Posted by kivohs View Post
    Hi Umi,
    I dont think there is any need to create a library or anything.
    In netbeans there is an option to create a package . Right-click on src folder and create one using that and then you can import your package just like you import java packages (java(x). xyx.* or something like that)
    I know, but if I do like that, only one project will be able to import this package. And adding this package to every project I'm going to create seems rather dumb. Then I would add it as a library instead.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,750
    Rep Power
    19

    Default

    Is this package (which was presumably another project) jarred up?

    If so, then simply right click on the Libraries bit in the Projects explorer, select add JAR/Folder, and then browse to where your jar file is. No need to mess with the system classpath (not generally a good idea), or stick stuff into the JRE lib (always a bad idea).

Similar Threads

  1. How to import a Java package?
    By tyang in forum New To Java
    Replies: 4
    Last Post: 02-06-2010, 09:14 PM
  2. Eclipse "import not resolved" package problem?
    By spamsickle in forum New To Java
    Replies: 3
    Last Post: 08-24-2009, 11:44 AM
  3. Help Needed to import package
    By gradStudent in forum New To Java
    Replies: 10
    Last Post: 08-11-2009, 01:37 AM
  4. How to import a package before it is compiled
    By gradStudent in forum Advanced Java
    Replies: 1
    Last Post: 08-11-2009, 12:17 AM
  5. How to import a package in Eclipse?
    By naipulb in forum New To Java
    Replies: 2
    Last Post: 06-09-2008, 11:04 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
  •