aspose file tools*
The moose likes Beginning Java and the fly likes Please heeelp..Can't get Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Please heeelp..Can Watch "Please heeelp..Can New topic
Author

Please heeelp..Can't get "packages" to work

Con Lu
Ranch Hand

Joined: Aug 27, 2002
Posts: 38
Hi,
I have a really frustrating problem, which I have been unable to solve for some time now. I have followed the instructions in a number of books but it still doesn't work. Can anybody help me?
The problem:-
I want to create a package on my computer, but when I try to import the package in a class on another directory, the package cannot be found by the compiler.
For example the package I want to set up is com.p1.lu and inside that package I want a class named Class1.java
The Steps I have done are as follows:-
1) On my WIN98 laptop, create the directories c:\com\p1\lu
2) Inside the directory lu created a class Class1.java with the following code:-
package com.o1.lu;
public class Class1{
public void setName(String name){
System.out.println(name);
}
}
Code compiles fine
3) Change my class path on my autoexec by the following:-
set CLASSPATH = .;c:\com\p1\lu
4) Rebooted my computer
5) At DOS prompt checked that the class path is correct by entering set
6) In another directory on my computer create a class named TryPackage.java with following code:-
import com.p1.lu;
public class TryPackage{
public static void main(String []args){
Class1 obj = new Class1();
obj.setName("David");
}
}
Does NOT compile with following error message:-
TryPackage.java:1 ackage com.p1.lu does not exist
Any help would be much appreciated. I have been tearing my hair out over this for quite some time now.
Regards,
Con
P.S.I also ran into another problem which might be related - I tried to run the "Hello World" example in JBuilder7 and a similar compiler error resulted with the package name.
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Your problem here seems to be a simple "typo".
package com.o1.lu;
public class Class1{
surely that should be com.p1.lu ?


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Joel Cochran
Ranch Hand

Joined: Mar 23, 2001
Posts: 301
Your classpath setting needs to be c:\ instead of c:\com\p1\lu.
For instance, on my system I have a Packages directory that I put all my packages in, so the structure is like so...

c:\
packages\
com\
domain1\
package1
package2
domain2\
package1
package2
My classpath statement include c:\packages, the directory ABOVE my actual package directory. Now I can actually find all these packages by importing com.domainX.packageName
HTH
[ August 27, 2002: Message edited by: Joel Cochran ]

Wait a minute, I'm trying to think of something clever to say...<p>Joel
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
con,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please heeelp..Can't get "packages" to work