aspose file tools*
The moose likes Beginning Java and the fly likes running javac from any folder Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "running javac from any folder" Watch "running javac from any folder" New topic
Author

running javac from any folder

Dan Maples
Ranch Hand

Joined: Jun 21, 2004
Posts: 153
hey guys, I am tying to set up the java compiler on a new computer, I downloaded the jdk and the compiler works, but it only works when I'm in C:\Program Files\Java\jdk1.5.0\bin. Is there a way to make it so that both the compiler and the jvm work in any folder on the computer? or at least a different specifed folder?
-Thanks Dan


-Dan
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9047
    
  10
You need to add {JAVA_HOME}/bin to your PATH
where {JAVA_HOME} is the home directory of your java installation (like C:\j2sdk.1.4 ...)


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Dan Maples
Ranch Hand

Joined: Jun 21, 2004
Posts: 153
can you explain to me how to do that please?
Thanks- Dan
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
How the PATH is set depends on your operating system. So, what are you running?

Note that the steps to set most any operating system environment variable for a particular operating system are about the same. So, you be able to figure it out by taking a look at HowToSetTheClasspath for the steps to take.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
kiran vydhyam
Greenhorn

Joined: Jul 22, 2004
Posts: 7
Hi Marilyn,

I have done this,I have set the path as
C:\j2sdk1.4.2_04\bin;c:\j2sdk1.4.2_04\bin\javaexamples1
When I try to run the files of javaexamples1 from c:> error cannot read.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
What exactly are you doing to get exactly what error message?

Please post your question in a new thread if the topic is different.
kiran vydhyam
Greenhorn

Joined: Jul 22, 2004
Posts: 7
Excuse me for the confusion,I was referring to the same above thread topic.
I'am trying to run the java source files from c:> ,for this I have set the path to
c:>j2sdk1.4.2_04\bin\javaexamples
I have my source files in javaexamples folder.
Even though the files don't get executed.It gives an error message as
Error: Cannot read A.java
Anders Engstr�m
Greenhorn

Joined: Jul 25, 2004
Posts: 4
You should only add the path to the executable files (javac.exe, java.exe and so on) found in c:>j2sdk1.4.2_04\bin to the PATH. This is to help your OS find the commands you want to use. When this is done you should be able to compile and run your java-files in any folder on your computer.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9047
    
  10
If you are having trouble compiling (javac ...), you need to set your PATH.
If you are having trouble running the compiled classes, you need to set your CLASSPATH. I can't see from your question which you are having problems with.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Again, what exactly are you doing to get exactly what error message?

It might help if you were to clarify, exactly what command are you executing.

Also, note that you can't run a source file. You first need to compile them, and then run a class.
[ July 26, 2004: Message edited by: Dirk Schreckmann ]
Ken Okoli
Greenhorn

Joined: Dec 19, 2003
Posts: 3
kiran vydhyam
Error: Cannot read A.java, right?
I used to have a similar problem. I think the editor you are working on is adding it's own extension to your java file. For example when you save you have something like: A.java.txt right?
This time, when you save, include " ". For example, "A.java"
That should allow javac to read A
Maybe to hide extensions for known file types may be permanent.


KNOWLEDGE IS POWER.....SPREAD THE LOVE
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: running javac from any folder