wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Javac.exe not staying open Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Javac.exe not staying open" Watch "Javac.exe not staying open" New topic
Author

Javac.exe not staying open

C.A Reynolds
Greenhorn

Joined: Dec 10, 2005
Posts: 5
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

Joined: Jul 08, 2003
Posts: 24183
    
  34

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!


[Jess in Action][AskingGoodQuestions]
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
C.A Reynolds
Greenhorn

Joined: Dec 10, 2005
Posts: 5
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

Joined: Aug 31, 2004
Posts: 11343

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

Joined: Dec 10, 2005
Posts: 5
Thanks. I'll try that now.

I appreciate all the help everyone
C.A Reynolds
Greenhorn

Joined: Dec 10, 2005
Posts: 5
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

Joined: Aug 31, 2004
Posts: 11343

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

Joined: Feb 24, 2004
Posts: 236
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 ]

Paul M. Santa Maria, SCJP
C.A Reynolds
Greenhorn

Joined: Dec 10, 2005
Posts: 5
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Javac.exe not staying open