wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Problem setting classpath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Problem setting classpath" Watch "Problem setting classpath" New topic
Author

Problem setting classpath

Asmita Khamkar
Greenhorn

Joined: Mar 28, 2009
Posts: 25
Hi,
I am preparing for SCJP 1.5, I was having problem accessing public classes from different packages or default classes from same package. To resolve this problem I got a suggestion to set the classpath, but when I tried to do that it has created a new problem.

Instead of running the code on giving the command classname.java it opens the notepad
file in which the code is stored. The classpath which I set was set CLASSPATH=c:\scpprac;.; scpprac is a folder which has 2 more packages in it cert , exam & within exam, stuff package. I also tried set CLASSPATH=c:\scpprac\cert;.; . My operating system is Windows Vista (Basic).

I hope I would get a solution. Thank you in advance.
ashik chollangi
Greenhorn

Joined: Jun 06, 2008
Posts: 15
I dont know much about this classpath once I had set it to a location and then there was no prob ..My location was D:\java programs!!\


Im 4 Java
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874



Asmita , Welocme to Javaranch !!

Are you trying to run the java ? If setup the classpath CLASSPATH=c:\scpprac;.;

has 2 more packages in it cert , exam & within exam, stuff package


If i get your problem right ... Here cert and exam are considered package name as they are directly under CLASSPATH , stuff package should be either plcaed inside scpprac or add CLASSPATH with c:\scpprac\exam.
Asmita Khamkar
Greenhorn

Joined: Mar 28, 2009
Posts: 25
Hi,
Sorry but the problem is still not solved. Its still openinig the notepad file instead of running the code.
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874


how do you run it ? Please tell the details.
Asmita Khamkar
Greenhorn

Joined: Mar 28, 2009
Posts: 25
c:\scpprac\cert>javac Beverage.java

c:\scpprac\cert>Beverage.java

Beverage is the name of class with in cert package.

This is the code in Beverage.java file

package cert;
public class Beverage
{
public static void main(String[] args)
{
System.out.println("H");
}
}

I tried to set the classpath as

set CLASSPATH=c:\scpprac\cert


Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874



c:\scpprac\cert>javac Beverage.java

c:\scpprac\cert>Beverage.java


Are you sure , this is the command to run a java file.

type "java Beverage" in cmd line. to run a class file. Also better leave all the packages as of now and try to compile and run a simple java program.

I would recommend you to read Java beginners book or some online tutorials" Heres one. check it out.
Asmita Khamkar
Greenhorn

Joined: Mar 28, 2009
Posts: 25
Hi,
Thank you for pointing out its not classname.java, I am really sorry it was due to confusion as it's not working, but its still not working even if i give java Classname . Thank you once again.
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874



I am really sorry it was due to confusion as it's not working, but its still not working even if i give java Classname


One thing to note is just saying "its still not working" will not make people to help you.

Say the error and steps you have done so far. to be more clearer for the Ranchers here to help.

Check the link i have provided and see if you have basic steps need to run Java. What do you get when you simply type "java" in cmd.
Asmita Khamkar
Greenhorn

Joined: Mar 28, 2009
Posts: 25
Hi,
Thank you the classpath problem solved as other codes I had written before are working properly now, but problem in Beverage code is package level problem, I'll try to solve it. Thank you for the help.
vijay saraf
Ranch Hand

Joined: Jan 08, 2005
Posts: 141
Asmita...do these things..

set your classpath as

set CLASSPATH=.;c:\scpprac;

then go to cert dir and compile

c:\scpprac\cert>javac Beverage.java

if it compiles successfully then run your program as

c:\scpprac\cert>java cert.Beverage


Thanks
Vijay Saraf.
Asmita Khamkar
Greenhorn

Joined: Mar 28, 2009
Posts: 25
Hi Vijay,
Thank you very much all my doubts & queries regarding classpath & package are clear now. Thank you once again
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem setting classpath
 
Similar Threads
Classpath and JAVA_HOME doubt
Problem in setting CLASSPATH
Classpath, packages, huh?
add all subfolders to classpath
Execute Java Classes from command line