• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your problem here seems to be a simple "typo".
package com.o1.lu;
public class Class1{
surely that should be com.p1.lu ?
 
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
reply
    Bookmark Topic Watch Topic
  • New Topic