1 Attachment(s)
current directory not dectected by java application launcher in command prompt
Here is the following scenario
my classpath in environment variables is .;D/Javarohan; (current directory already specified)
my files are in location D:/Javarohan/In2
Filename in In2 directory is Bwoi.java (i have written the package statement in the Bwoi.java file.....package In2;)
Now when i go to command prompt and go to the directory and issue the javac as
D:/Javarohan/In2>javac Bwoi.java [Compiles fine]
and next
D:/javarohan/In2> java Bwoi [Press enter]
I get the following no class definition found error
and if i isuue command like below
D:/Javarohan/In2> java In2.Bwoi [I am getting hte right output]
Attachment 689
I mean when i am in the required directory as according to my CLASSPATH set [.;D/Javarohan;],why should i explicitly issue
the command java In2.Bwoi..Why doesnt it work with java Bwoi ?. This clearly means java application
launcher is not detecting my current directory when i have already specified the dot operator in
CLASSPATH ->.;.D/Javarohan;
is there any solutions for running it in thru command promt by going into the directory D:/Javarohan/In2
and issuing a command like this->java Bwoi
What are the changes i need to do as far as CLASSPATH goes and my package statement in Bwoi.java file?
Please help me out guys ! its funny:cool: but serious :mad:
Re: current directory not dectected by java application launcher in command prompt
To execute a class in a package, you need to position the current directory to the directory containing the top of the package path folder and use the full package path for the class.
For a package in In2, go to the folder containing In2 (Jovarohn) and enter:
java In2.Bwoi
To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'
Paste here.
Re: current directory not dectected by java application launcher in command prompt
Hey thanks for ur timely reply(Ya i will do it like u said for command prompt copying....sorry for putting up an image).
But my problem is unsolved.Why should i once again say java In2.Bwoi after compiling to execute it whereas i have already included the current
directory in my classpath and both .class file and source file of Bwoi is in In2 folder.And I am in In2 directory in command prompt. why cannot it be directly java Bwoi instead of java In2.Bwoi since JVM searches for .class file in my current directory.I guess it might be a compulsory rule
Re: current directory not dectected by java application launcher in command prompt
If a class is in a package then the classpath must point to the start of the package path.
The fully qualified name of the class includes the package. Bwoi is not the full name of the class. It needs to have the package also.
If you know how many directory levels you must go up to get the the beginning of the package path you can use: ..\ in your classpath.
For example, if you are in the In2 folder:
java -cp ..\. In2.Bwoi
Re: current directory not dectected by java application launcher in command prompt
the file name needs to be the same as the class name. If the class name is In2, then the file name should be In2.java.