aspose file tools *
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes import and package... ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "import and package... ?" Watch "import and package... ?" New topic
Author

import and package... ?

Ayman Jaffar
Ranch Hand

Joined: Sep 06, 2000
Posts: 57
Hi all,
Is there a "classes" directory in my JDK1.3 or do I have to create it under c:\jdk1.3\jre ?
And is this the place where I can make my packages without having to set my classpath variable.
If yes, why isn't it working for me !!!
My OS is Win98,
thanks
[This message has been edited by Ayman Jaffar (edited December 18, 2000).]


america
David Harrigan
Ranch Hand

Joined: Dec 12, 2000
Posts: 52
Bit ambiguous, but I'll try.
You don't have to create any classpath directory. Simply set JAVA_HOME to point to the install directory of Java, i.e., on my system I have:-
set JAVA_HOME=c:\jdk1.3
you may also want to add the path to the bin directory as well,
set PATH=$PATH;c:\jdk1.3\bin
David.
Rob Ward
Greenhorn

Joined: Dec 14, 2000
Posts: 8

I'm not sure exactly what you're asking here, so please forgive me if I answer the wrong question.
You can put packages and JARs in the directory C:\jk1.3\jre\lib\ext, and you will not need to explicitly set the classpath to find these. This is intended for JAR files that you might use frequently (ext = extensions), such as crypto classes.
Note that a common gotcha here is to be sure that if you have put the classes in C:\jk1.3\jre\lib\ext, that you are actually using c:\jdk1.3\bin\java, and not some other jvm.
I haven't heard of there being a feature that you describe (eg. putting classes in jdk1.3\jre\classes), although I suppose it is possible there is - I don't have jdk1.3 on this machine to test that theory. If the feature does indeed exist it doesn't sound like something I'd advise anyone use though. You're much better off setting the classpath explicitly (in your environment or via the -classpath flag) so that always you know exactly what classes are in your classpath. Inadvertently leaving old classes in your classpath can lead to a lot of confusion!
Rob


------------------
Rob Ward
rob.w@mail.com
"Maths and alcohol do not mix. Remember, don't drink and derive"


Rob Ward<BR> <A HREF="mailto:rob.w@mail.com" rel="nofollow">rob.w@mail.com</A> <P><I>"Maths and alcohol do not mix. Remember, don't drink and derive"</I>
Ayman Jaffar
Ranch Hand

Joined: Sep 06, 2000
Posts: 57
Okay,
what I mean, is that
1- I've created a directory under "c:\jdk1.3\jre" which is called "classes" (i.e. c:\jdk1.3\jre\classes) and I've the following package under the classes directory "salute.american" (i.e. c:\jdk1.3\jre\classes\salute\american)
2- then I've created a .java and .class file under them....(i.e. c:\jdk1.3\jre\classes\salute\american\Hi.class and Hi.java)
3- I can access the Hi.class from anywhere (from any java file in any directory such as (c:\delete\ImplementingSalutes.java) when I put "import salute.american.Hi;" BUT if I put "import salute.american.*; there will be a compile error when I try to access the Hi class (i.e new Hi() ), so why is ther e a compile error?
umm.........I hope this description is not too boring, but I've been trying solve the problem for some time.
Thanks
[This message has been edited by Ayman Jaffar (edited December 18, 2000).]
Axl Rose
Greenhorn

Joined: Dec 18, 2000
Posts: 16
I think what you need to do is a simple set classpath statement.
assuming that you are using a dos command to compile and run your program , you still need to set the class path of your package so that other classes (any where) can see them in an import statement.
for example (assuming that you are working in a dos window)
you use
C:\>set classpath=%classpath%;c:\jdk1.3\jre\classes
after that, if you try to compile the class that contains the import statement, it should not give you any error about can't find the class error message.
if you are using some other development environment like the JBuilder or Kawa, there is an equivalent setting,but using menus rather than standard DOS style.
buttom line: your problem can be solve if you play with your classpath setting.
try the above method, if it didn't work , tell me
Ayman Jaffar
Ranch Hand

Joined: Sep 06, 2000
Posts: 57
I'm sorry for this very late reply, but I was rather busy with urgent problems....glad all is okay..
about you enquiry.
1- I created my own "classes" directory under "c:\jdk1.3\jre"
2- then I set the "classpath" variable in my autoexec.bat like this : SET CLASSPATH = %CLASSPATH%;c:\jdk1.3\jre\classes ...I'm not sure if you need the word "set" at the beginning of the line, especially if I've already declared a "classpath" variable
3- abra cadabra, then you use the import statment to access the class files under "classes directory". I'd write "import salute.american.*;" which are under "classes\salute\american"
4- that all !!
and it works for me. also if I add more packages under "classes" they still all work.
please tell me if you have any questoins and sorry for the late reply :]
Regards
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: import and package... ?