File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java command

 
Sharan Ashok Vasandani
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

when i am running a program,java command is checking for the class file in the current directory also by default.even if i have not set the current directory in classpath.why so?

Regards,
Sharan
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The classpath search is specified in this documentation. Read that, and if you cannot find the answer to your question, then ask again.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are having an actual problem then please post your CLASSPATH setting and your complete java command. You get your CLASSPATH setting with echo $CLASSPATH (unix) or echo %CLASSPATH% (windows).
 
Remko Strating
Ranch Hand
Posts: 893
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe I do something wrong, but if I try that on my machine on Windows I get
%classpath%

It just writes what I type.

After doing some playing around I discoverd that I didn't have set a classpath, because the variable echo %java_home% is working

So if windows repeats your environment variablet his means it isn't set.

I don't experience problems without my classpath setting. So why should I set it then??
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by wilhelm tell:
Maybe I do something wrong, but if I try that on my machine on Windows I get
%classpath%

It just writes what I type.

After doing some playing around I discoverd that I didn't have set a classpath, because the variable echo %java_home% is working

So if windows repeats your environment variablet his means it isn't set.

I don't experience problems without my classpath setting. So why should I set it then??


Thanks for your input Remko, but let's concentrate on Sharan's problem.
 
Sharan Ashok Vasandani
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C:\Documents and Settings\sharanv>cd..
C:\Documents and Settings>cd..
C:\>set path=c:/jdk1.5/bin;
C:\>cd sharan C:\sharan>javac myclass.java
C:\sharan>java myclass
Hiiiii
C:\sharan>

i have not set any classpath at the command prompt,and there are no environment variables set. how is the command able to find my class file named "myclass", As per books this should not run,as java does not search for the classes in the current directory by default. then how is this working.please explain. Regards, Sharan
 
Sharan Ashok Vasandani
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C:\sharan>echo %classpath%
%classpath%

C:\sharan>cd..

C:\>echo %classpath%
%classpath%

C:\>

Above is the value for classpath variable.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sharan Ashok Vasandani:
...As per books this should not run,as java does not search for the classes in the current directory by default...

How old are these books?

Please review the documentation using the link Barry provided above.
 
Ashok Kumar
Ranch Hand
Posts: 93
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The SUN documentation clearly states
The default class path is the current directory. Setting the CLASSPATH variable or using the -classpath command-line option overrides that default
.So unless you specify a classpath(In your case you have not) it will consider the current directory.
 
Sharan Ashok Vasandani
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\sharanv>cd..

C:\Documents and Settings>cd..

C:\>set path=c:/jdk1.5/bin;

C:\>set classpath=c:/temp;

C:\>cd sharan

C:\sharan>java myclass
Hiiiii

C:\sharan>set classpath=c:/temp

C:\sharan>java myclass
Exception in thread "main" java.lang.NoClassDefFoundError: myclass

C:\sharan>set classpath=

C:\sharan>java myclass
Hiiiii

C:\sharan>set classpath=;

C:\sharan>java myclass
Hiiiii

C:\sharan>set classpath=c:/temp;

C:\sharan>cd..

C:\>java myclass
Exception in thread "main" java.lang.NoClassDefFoundError: myclass

C:\>set classpath=c:/temp;

C:\>cd sharan

C:\sharan>java myclass
Hiiiii

C:\sharan>

ok,agreed that defualt classpath is current directory,but then why it is not diplayed when i do echo %classpath%.

second i also tried to run the program after setting some absurd classpath,still the current directory is being searched if i ended the classpath declaration with a semicolon( ,bt if i do not end the classpath declaration with semicolon( then its not searching in the current directory.

if i suppose that it is taking the blank space after semicolon to be current directory for that i tried to set the
c:\>set classpath=c:/temp;,and then i again went to c:\sharan> and tried to run the program and yes its running.you can see that in above pasted screen.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On windows the semicolon ";" is a path separator character - you should not be using it at the end of the path. If you wish to refer to the current directory you should use ".".

But I found this Bug Report

If you read the post at the bottom of the bug report the poster claims that an empty path element would also mean the default directory.

Also, if you search the web you will find several discussions of whether ";;" (or "::" in the case of unix) should be taken to mean "." or just be ignored.
[ February 23, 2007: Message edited by: Barry Gaunt ]
 
Sharan Ashok Vasandani
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i read that webpage that implies even if there is no blank space purposely inserted before or after ; it will take it as a blank space and hence include current directory.
means

the following two are same
1)c:\>set classpath=;
2)c:\>set classpath= ;

my question is that even if i have not left a space after = in the 1) classpath it is same as leaving a blank space after = like i have done it in 2) classpath?why so?
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic