Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Javac.exe not staying open

 
C.A Reynolds
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am brand new to java. So new, that I'm trying to get the classic "Hello World" program to compile and when I run javac.exe the prompt stays open for less than a second (you can see that its scrolling something) and then immediately closes.

Any ideas?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

"javac.exe" is a command-line program. You have to run it by typing "javac" at a command prompt -- i.e., the "MS-DOS Window". Typing "javac.exe" into the "Start | Run..." dialog isn't going to do you much good. Let me lean over and look at my wife's XP box... Start | Programs | Accessories | Command Prompt. You should get a nice black window. Type your commands in there!
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

Are you using Jview, by chance? If so, see this page.

Otherwise, are you running directly from the Command Prompt (I'm assuming you're using Windows)? What exactly are you entering at the prompt?

Since you mentioned "javac.exe," I'll just add that you do not type a ".exe" extension when running javac. Simpy type "javac" (without quotes), followed by a space and then the name of your file (including the .java extension)...

javac MyClassName.java
 
C.A Reynolds
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When using the dos prompt, I went into the directory where my sample java program is (which is not in the same folder as the JDK software)

and then I typed "javac sample.java"

I got this as a error " 'javac' is not recognized as an internal or external comand, operable program or batch file."
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by C.A Reynolds:
... I got this as a error " 'javac' is not recognized as an internal or external comand, operable program or batch file."

Basically, you need to tell your system where to find Java, and you will probably want to do this by setting your PATH variable. Here are instructions for doing this.
 
C.A Reynolds
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. I'll try that now.

I appreciate all the help everyone
 
C.A Reynolds
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
setting the path permanently doesn't seem to be working so I just ran javac while in the directory it was installed in and told it to compile my sample.java file.

I got this error
"error:cannot read: sample.java
1 error"

Does this mean there is a problem with the code? Or does this mean it can't read the file because it's in a different directory?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That error is because your sample.java file is in a different directory. If you've changed your directory to where javac is installed, then I think you would need to type the full path after "javac." Something like...

javac C:\MyJavaStuff\etc\sample.java

What isn't working about setting your PATH? Which operating system are you using?

(After setting the PATH variable, I know that you would at least need to close the Command Prompt and re-open to start a new session. But you might need to reboot the machine as well.)
 
Paul Santa Maria
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi -

I'd definitely encourage you to consider getting some kind of graphical IDE - it sounds like you'd probably be much more comfortable with a GUI than the command line. Here are a couple of good Open Source choices:

Netbeans:
http://www.netbeans.org

Eclipse:
http://www.eclipse.org

But back to your immediate problem: getting a simple Java program compiled. Please do this:

1. Start a "command prompt"


2. Create a .bat file to set your environment:
From the command prompt, type:
notepad


NOTES:
You need to have the quote ('"') and percent ('%') characters exactly like I have them. Feel free to cut and paste from this note.

You need to find the actual path where you installed your JDK. One way is to find it in Windows Explorer. Another is to just re-install it.

3. Save your environment file as "env.bat"
<= From notepad, do a "File, Save As..."
Be *SURE* to Go into the pull-down dialog and set "Save as Type" to "All Files". This is very important - or notepad will always try to save your file with the suffix ".txt". And it won't work.

From notepad, select:


4. Create a "Hello.java" source program:
From the command prompt, type:
notepad


5. Save "Hello.java":
From notepad, select:


6. OK: we're nearly done! Promise! Go to the C:\ root directory.
From the command prompt:


7. Whew!
After all that, hopefully, you'll see the text "Hello, Java!" printed out...
[ December 10, 2005: Message edited by: Paul Santa Maria ]
 
C.A Reynolds
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everyone! I made a bat file that sets my path and everything and I just run it in the command prompt before i do any compiling or running and everything works now.

Thanks for all the help! Now I can get to the actually programming aspect of java lol
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic