Results 1 to 11 of 11
  1. #1
    fatabass is offline Senior Member
    Join Date
    Nov 2011
    Location
    Turkey
    Posts
    380
    Blog Entries
    24
    Rep Power
    3

    Default How can I use my own classes ? ( How do I import them ? )

    In folder: "C:\MyClasses\myPackage" I have two files:

    MyPrintClass.java and MyPrintClass.class

    From Windows, I have set Environment Variables:
    CLASSPATH: .;C:\MyClasses
    and Path: C:\Program Files\Java\jdk1.6.0_26\bin;C:\MyClasses

    but i still cant import this myPackage. What am I doing wrong?

    The java file is:

    Java Code:
    package myPackage;
    
    public class MyPrintClass 
    {
    	public static void print(String s)
    	{
    		System.out.println(s);
    	}
    }
    Thank you.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,335
    Rep Power
    25

    Default Re: How can I use my own classes ? ( How do I import them ? )

    Post the layout of the files in the folders, the commandline used to compile and the full text of the error message.

  3. #3
    fatabass is offline Senior Member
    Join Date
    Nov 2011
    Location
    Turkey
    Posts
    380
    Blog Entries
    24
    Rep Power
    3

    Default Re: How can I use my own classes ? ( How do I import them ? )

    Answering my own question:

    I tried it from command line and it worked. It seems there is something wrong with Eclipse.

    New question:

    How do I tell Eclipse that I have a new Classpath ?

  4. #4
    fatabass is offline Senior Member
    Join Date
    Nov 2011
    Location
    Turkey
    Posts
    380
    Blog Entries
    24
    Rep Power
    3

    Default Re: How can I use my own classes ? ( How do I import them ? )

    Thanks Norm, just saw your response after I posted mine.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default Re: How can I use my own classes ? ( How do I import them ? )

    You never need to import classes in the same package.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    fatabass is offline Senior Member
    Join Date
    Nov 2011
    Location
    Turkey
    Posts
    380
    Blog Entries
    24
    Rep Power
    3

    Default Re: How can I use my own classes ? ( How do I import them ? )

    Oh no, there is nothing in the same package.

    MyPrintClass.class is in a separate folder, and I want to use it in all my projects, so I would like to import it.

  7. #7
    fatabass is offline Senior Member
    Join Date
    Nov 2011
    Location
    Turkey
    Posts
    380
    Blog Entries
    24
    Rep Power
    3

    Default Re: How can I use my own classes ? ( How do I import them ? )

    I saw this: How can I import my classes?

    And problem solved. So Eclipse doesn't really know about the Classpath, it needs another import from the menu.

    Thanks.

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default Re: How can I use my own classes ? ( How do I import them ? )

    Don't confuse imports with the run time classpath. Imports are just semantic sugar that allow you to use an unqualified class name elsewhere in your code.

    Classes used in your code must be accessible on the compile time classpath. This is true whether you import the classes or use the fully qualified names.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default Re: How can I use my own classes ? ( How do I import them ? )

    And I don't know what you mean by 'menu' here:
    it needs another import from the menu.
    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,335
    Rep Power
    25

    Default Re: How can I use my own classes ? ( How do I import them ? )

    The IDE's menu

  11. #11
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default Re: How can I use my own classes ? ( How do I import them ? )

    Oh. I use NetBeans, and the only menu I'm aware of related to imports is 'Fix imports' -- which I seldom use, since autocompletion of class names plugs in the import at the top of the class. I guess Eclipse does things a little differently.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. How can I import my classes?
    By Pojahn_M in forum Eclipse
    Replies: 3
    Last Post: 10-07-2011, 12:53 AM
  2. static import only from classes and interfaces
    By balajir in forum New To Java
    Replies: 3
    Last Post: 12-13-2010, 05:31 AM
  3. Import
    By gothrog in forum Java Applets
    Replies: 2
    Last Post: 05-13-2010, 11:16 PM
  4. Can not import jxl.*
    By AnnieDing in forum Java Servlet
    Replies: 3
    Last Post: 01-22-2010, 03:52 PM

Posting Permissions

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