hi friends, any one of u please give me the explanation of what setting a classpath exactly means? after writing a class and putting it inside a package, i am not able to run the class from the place where i had stored it.for example if my class named xyz is in c:\mypack\xyz, i am not able to run the file frm the same location.i am able to run the file only from c:,is it anythg related to setting the classpath? regards, raja
Classpath is an environment variable which the jvm uses for finding a particular class. The current directory is default in the classpath
for eg. what in windows do u do to find a file?...
for eg> suppose u are having file A.java in d:\test1\ suppose u are having file B.java in d:\test2\ thus if u are using file B in A may b by creating Object of B in A. u will need to have B in classpath of A. So, that when u try to compile file A, jvm can see where the file B is...
command on windows may b like this : set classpath=%classpath%;d:\test1
where %classpath% is used to include the existing classpath so that it dosent get overriden.. [ March 07, 2005: Message edited by: Nischal Tanna ]
What you have to realize about this article is that the author starts out by giving you "how to do it wrong" so that you hopefully will have an understanding about how it works.
How to do it right is:
Both when compiling and when running a class, set your current directory to the root directory from which your folder tree branches out. In your case, you should set the current directory to c:\raiz.
Both when compiling and when running a class, Always include the current directory in your classpath (-cp = ".") along with whatever other classes you need.
the following should compile both classes:
When running the class, use the following:
Having said this, realize that for large java projects, this isn't a very convenient way to compile. Most developers will either use ANT, which is an open source build tool, or they will use an Interactive Development Environment (IDE) such as Eclipse or NetBeans that compiles for them. [ March 08, 2005: Message edited by: Merrill Higginson ]