permaculture playing cards*
The moose likes Beginning Java and the fly likes Pac kages...again Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Pac kages...again" Watch "Pac kages...again" New topic

Pac kages...again

Patrick Tibbetts

Joined: Jan 06, 2002
Posts: 20
Hi again!
I posted not to long ago about classpath. Well, I thought I was feeling pretty stupid, but it turned out I was right to begin with so thank you all for reassuring me that I was not having a brian lapse or something. My paths were correct.
My problem is when I start using packages. Then I get errors like 'errors: can not read...'
This is frustrating since my apps work, until I place them into a package.
I set my paths to look into those packages, I was on the Sun site and it seemes like everything is set right.
Package name: jfiles under my d:\
My Classpath points to this folder first, the where I keep the JDK.
I am open to anything.
Thanks in advance for any advice !
Neil Laurance
Ranch Hand

Joined: Jul 18, 2002
Posts: 183
Which version of JDK do you have?
-classpath or $CLASSPATH specifies the directories, JARs and ZIPs to search through to find a class. In versions 1.0 and 1.1, this path relates to the location of system classes, extension classes, and application classes. In 1.2 and later, it relates to the application classes only, so adding the path to your JDK is not required. Also remember that it is not sufficient to specify a directory containing JARs that you may be using - instead, each JAR must be added to the classpath separately.
Hope this helps, Cheers Neil
Patrick Tibbetts

Joined: Jan 06, 2002
Posts: 20
I am using JDK 1.3 (1.3.1_02 to be accurate)
I have my -classpath set in my environment variables as c:\jdk1.3.1_02\bin
I was assuming that was all I needed to do. The Sun site did say add the directories where the JRE should look in to run the apps. So i set it up as:
You are saying I should not have to add any other paths?
Like I said, everything works correctly until I use package declarations. Then I get the NoDefClassFoundError...
Neil Laurance
Ranch Hand

Joined: Jul 18, 2002
Posts: 183
Don't confuse classpath with path. One is used to search for compiled '*.class' files, the other is used for finding executable files. You should not need to add c:\jdk1.3.1_02\bin to your classpath. As an example of how you should set your classpath:
If for example, you have created 2 files like:
public class A {}
public class B {}
Then after compiling you should have two class files: A.class, and B.class. In order to be able to use these, you would need to place these files in a directory structure like:
--> com
-------> pt
--------------> A.class, B.class
Then you should add c:\some\path\to\my\package\root to your classpath
If create a jar file to hold your classes, you would need to:
[1] change to c:\some\path\to\my\package\root
[2] jar Mcf pt.jar com
Then you could place the jar file in another folder such as: c:\path\to\jars and you would need to add the following to your classpath:
Hope this helps
Don't get me started about those stupid light bulbs.
subject: Pac kages...again
Similar Threads
Class not found in Package
Question on Practice Exams Book from K&B
The ridiculous Problem
Missing packages mean what?