This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with PATH and PATH variables

 
Lalit Mehra
Ranch Hand
Posts: 384
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey all ,

i'm having a little problem sort of thing with my environment variables ...

actually last night the OS crashed ... p.s. i should have installed l inux instead.

anyways ... i installed the jdk at exactly the same location it was before ... @ D:/Installations/JDK

and set my env. variables to

PATH = .;D:\Installations\JDK\bin;D:\JFiles

CLASSPATH = .;D:\Installations\Tomcat 6.0\lib\servlet-api.jar;D:\Installations\JDK\bin;D:\JFiles


D:/JFiles is where i store my java class and source files ... it's not working now ... i do not know what but i think i'm not setting them exactly i should ...

please excuse me for this silly question ... as it was working fine before and i was the only one who set the env. variables ...

i read all about classpath on the internet ... googled it multitaskingly ... but found nothing ...

can anyone please ...
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it's not working now

What is not working ?? If you have an error message of some sort, please post it here.
 
Lalit Mehra
Ranch Hand
Posts: 384
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops ... mr. verre

actually i'm not being able to use java and javac providing the filename ... like this

D:\>javac Program1.java
javac: file not found: Program1.java
Usage: javac <options> <source files>
use -help for a list of possible options


and when i use the same like this

D:\Installations\JDK\bin>javac Program1.java

it runs

i'm sure there some problem with my env. variables ...
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm sure there some problem with my env. variables ...

I don't think so. Where is located the file Program1.java ? In D:\Installations\JDK\bin ?
 
Lalit Mehra
Ranch Hand
Posts: 384
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes sir ...
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no problem with your environment variables. You have to either:
1. Tell the compiler where the sources are by using an absolute path : javac D:\Installations\JDK\bin\Program1.java
2. or Tell the compiler where the sources are by using a relative path (relative to the current directory) : javac Program1.java (in D:\Installations\JDK\bin)

I may be forgetting other choices. Putting sources in the jdk's bin directory is a bad choice though. Keep your files out of there.
 
Lalit Mehra
Ranch Hand
Posts: 384
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i know all this mr. verre ...

and i do not keep my java files there ...

i keep them at D:/JFiles as i mentioned ...

the only thing is that previously i could just use the filename with javac no matter where my files are ... and no matter which current directory i am calling javac from ...
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the only thing is that previously i could just use the filename with javac no matter where my files are ...

You have found a way to make your compiler scan your all hard drive to find the source files ? I've never heard of this, sorry.
 
Lalit Mehra
Ranch Hand
Posts: 384
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no not exactly ... i meant that the files obviously were stored at the locations provided with the PATH and CLASSPATH
 
Lalit Mehra
Ranch Hand
Posts: 384
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
one more thing sir ...

if i'll compile the file using the absolute path then how am i going to run it using absolute path ... i can't get that one right
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lalit Mehra wrote:no not exactly ... i meant that the files obviously were stored at the locations provided with the PATH and CLASSPATH

Let's make things clear

1. PATH is used to find executable files. Putting the JDK's bin directory allows you to execute the JDK's programs (javac, java...) from anywhere.
2. CLASSPATH is used to find compiled classes and JAR files. This tells the compiler and the JRE where to find classes. This allows you, for example, to compile some source from directory A, which uses some JARs from directory B. (There are other usages). This also allows you to run some classes from a different directory.

So what I believe it that you could run class files in D:\JFiles from anywhere, because D:\JFiles is in your PATH. What I don't believe is that you could compile classes from outside D:\JFiles, without telling the compiler where to look for the sources.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if i'll compile the file using the absolute path then how am i going to run it using absolute path ... i can't get that one right

Sorry, I don't understand your question.
 
Lalit Mehra
Ranch Hand
Posts: 384
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dear sir,


i think i confused you too ....
all i meant was ...

to compile do like this
D:\>javac D:\Installations\JDK\bin\Program1.java

to run ... ???
D:\>java ??? --> what to right here ...
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to compile do like this
D:\>javac D:\Installations\JDK\bin\Program1.java

This will create Program1.class in D:\Installations\JDK\bin.


to run ... ???

You have to understand that the java runtime will look for your class into any directories or JARs set in your CLASSPATH. If D:\Installations\JDK\bin is in your CLASSPATH, you can run it from anywhere, using "java Program1". You can also use the -cp flag : "java -cp D:\Installations\JDK\bin Program1". If it isn't in your CLASSPATH, you need to go D:\Installations\JDK\bin, and if the current directory is in your CLASSPATH, you can run "java Program1". To put the current directory in your CLASSPATH, you can use "java -cp . Program1".
 
Lalit Mehra
Ranch Hand
Posts: 384
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks sir ....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic