Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem setting classpath

 
Asmita Khamkar
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!\
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Sorry but the problem is still not solved. Its still openinig the notepad file instead of running the code.
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

how do you run it ? Please tell the details.
 
Asmita Khamkar
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Asmita Khamkar
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vijay,
Thank you very much all my doubts & queries regarding classpath & package are clear now. Thank you once again
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic