• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding ClassPath

 
Deepak Bobal
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a class at

C:\Documents and Settings\Administrator\Desktop\Richard\My

package My;
public class ABC
{
public void Add()
{
System.out.println("Hello World");
}
}

and another class PQR

at

C:\Documents and Settings\Administrator\Desktop

import My.*;
class PQR
{
public static void main(String[] arg)
{
ABC a=new ABC();
a.Add();
}

}

and at command Prompt i am at

C:\Documents and Settings\Administrator\Desktop>

and if i give

C:\Documents and Settings\Administrator\Desktop>javac -cp Richard PQR.java

it works fine

and generates class files

bur if i try to run

using

C:\Documents and Settings\Administrator\Desktop>java -cp Richard PQR

it gives ClassNotFoundException

How can it be ractified.

Thanks
 
Ankit Garg
Sheriff
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use this commend to run the program on windows

java -cp Richard;. PQR

and for linux or unix, use this command

java -cp Richard:. PQR
 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C:\Documents and Settings\Administrator\Desktop>java -cp Richard My.PQR

Add package name before classname.
 
Ankit Garg
Sheriff
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by punit singh:
C:\Documents and Settings\Administrator\Desktop>java -cp Richard My.PQR

Add package name before classname.


PQR class in not in My package...
 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I read the question wrong.
 
Deepak Bobal
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Ankit

java -cp Richard;. PQR

works

But why " ;. " is added at the end of classpath

what does it mean.
 
Ankit Garg
Sheriff
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It means that the JVM should look for class files in the Richard directory and then in the current directory. dot represents the current directory and semicolon is used to separate paths from each other in windows...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic