Results 1 to 11 of 11
- 01-27-2012, 07:10 PM #1
Senior Member
- Join Date
- Nov 2011
- Location
- Turkey
- Posts
- 378
- Blog Entries
- 24
- Rep Power
- 2
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:
Thank you.Java Code:package myPackage; public class MyPrintClass { public static void print(String s) { System.out.println(s); } }
- 01-27-2012, 07:41 PM #2
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.
- 01-27-2012, 07:41 PM #3
Senior Member
- Join Date
- Nov 2011
- Location
- Turkey
- Posts
- 378
- Blog Entries
- 24
- Rep Power
- 2
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 ?
- 01-27-2012, 07:42 PM #4
Senior Member
- Join Date
- Nov 2011
- Location
- Turkey
- Posts
- 378
- Blog Entries
- 24
- Rep Power
- 2
Re: How can I use my own classes ? ( How do I import them ? )
Thanks Norm, just saw your response after I posted mine.
- 01-27-2012, 07:44 PM #5
Re: How can I use my own classes ? ( How do I import them ? )
You never need to import classes in the same package.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 01-27-2012, 07:48 PM #6
Senior Member
- Join Date
- Nov 2011
- Location
- Turkey
- Posts
- 378
- Blog Entries
- 24
- Rep Power
- 2
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.
- 01-27-2012, 07:49 PM #7
Senior Member
- Join Date
- Nov 2011
- Location
- Turkey
- Posts
- 378
- Blog Entries
- 24
- Rep Power
- 2
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.
- 01-27-2012, 08:14 PM #8
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.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 01-27-2012, 08:15 PM #9
Re: How can I use my own classes ? ( How do I import them ? )
And I don't know what you mean by 'menu' here:
dbit needs another import from the menu.Why do they call it rush hour when nothing moves? - Robin Williams
- 01-27-2012, 08:19 PM #10
Re: How can I use my own classes ? ( How do I import them ? )
The IDE's menu
- 01-27-2012, 08:28 PM #11
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.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
How can I import my classes?
By Pojahn_M in forum EclipseReplies: 3Last Post: 10-07-2011, 12:53 AM -
static import only from classes and interfaces
By balajir in forum New To JavaReplies: 3Last Post: 12-13-2010, 05:31 AM -
Import
By gothrog in forum Java AppletsReplies: 2Last Post: 05-13-2010, 11:16 PM -
Can not import jxl.*
By AnnieDing in forum Java ServletReplies: 3Last Post: 01-22-2010, 03:52 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks