Results 1 to 13 of 13
- 05-30-2010, 12:57 AM #1
Member
- Join Date
- May 2010
- Posts
- 5
- Rep Power
- 0
Compiling/Running in Command Prompt
Hi,
I am trying to compile and run a java program from the command prompt, and I'm running into one problem after another. I've searched the net as well as this forum and haven't found a solution just yet.
I have windows 7, and a program saved as "practice.java". My command prompt reads:
C:\Users\gateway pc>
To compile, I've typed "javac practice.java", which is saved in a folder titled "Java Files".
When entered, I receive the error message:
javac: file not found: practice.java
Usage: javac <options> <source files>
use -help for a list of possible options
I've tried creating a classpath, and I've tried redefining the value of the path variable, but nothing seems to work. Any help would be greatly appreciated, thanks in advance.
- 05-30-2010, 01:00 AM #2
Senior Member
- Join Date
- Feb 2010
- Location
- Ljubljana, Slovenia
- Posts
- 470
- Rep Power
- 4
Java is case sensitive, are you sure you file isn't named Practice.java?
Ever seen a dog chase its tail? Now that's an infinite loop.
- 05-30-2010, 01:05 AM #3
Member
- Join Date
- May 2010
- Posts
- 5
- Rep Power
- 0
Thanks for the fast reply.
Yes, I double-checked. All characters are lowercase.
- 05-30-2010, 01:13 AM #4
Senior Member
- Join Date
- Feb 2010
- Location
- Ljubljana, Slovenia
- Posts
- 470
- Rep Power
- 4
Ah, I just skimmed through your post, just now I see you're trying to compile the file from a different folder. This doesn't work, to compile, you'll still need to navigate to the directory that contains the file, or specify the path, like this:
The classpath just enables you to run your programs from anywhere, lets say your .class files (compiled files) are in c:\java, if you have your classpath set to that directory, you can do this:Java Code:c:> javac c:\java\myprogs\Example.java
Java Code:c:> java Example
Ever seen a dog chase its tail? Now that's an infinite loop.
- 05-30-2010, 01:55 AM #5
Member
- Join Date
- May 2010
- Posts
- 5
- Rep Power
- 0
I just tried typing:
C:> javac C:\Users\gateway pc\Desktop\Java Files\practice.java
so that the entire line in the command prompt reads:
C:\Users\gateway pc> C:> javac C:\Users\gateway pc\Desktop\Java Files\practice.java
And there was no response, no errors, no comfirmations... It didn't create a practice.class file as expected.
- 05-30-2010, 02:11 AM #6
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
- 05-30-2010, 02:15 AM #7
Senior Member
- Join Date
- Feb 2010
- Location
- Ljubljana, Slovenia
- Posts
- 470
- Rep Power
- 4
Yup, if no messages are displayed, that means the compilation was succesfull.
Ever seen a dog chase its tail? Now that's an infinite loop.
- 05-30-2010, 02:25 AM #8
I don't understand how you didn't get something back from the javac command. Can you copy and paste from the command prompt window showing what you did.
When I try a path with a space in a folder name I get this:
C:\Documents and Settings\Owner>javac C:\Documents and Settings\Owner\test.java
javac: invalid flag: C:\Documents
Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
- 05-30-2010, 02:26 AM #9
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
- 05-30-2010, 03:11 AM #10
Have you tried using javac with a path containing a space?
The OPs post shows 2 spaces in the path.
C:\Users\gateway pc> C:> javac C:\Users\gateway pc\Desktop\Java Files\practice.javaLast edited by Norm; 05-30-2010 at 03:13 AM.
- 05-30-2010, 05:44 AM #11
Member
- Join Date
- May 2010
- Posts
- 5
- Rep Power
- 0
I really appreciate all the responses.
@ gcalvin & m00nchile
I searched my entire computer for a practice.class file and didn't find anything.
@Norm
Aside from what I've found on the internet thus far, I'm not too familiar with paths or how to change them. I removed the space in the file name containing the practice.java file, so now it is "JavaFiles". Here's my most recent attempt:
C:\Users\gateway pc>javac C:\Users\gateway pc\Desktop\JavaFiles\practice.java
javac: invalid flag: C:\Users\gateway
Usage: javac <options> <source files>
use -help for a list of possible options
- 05-30-2010, 08:31 AM #12
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
Yeah, "gateway pc" still has a space in it. Why don't you just cd into the JavaFiles directory before running javac? If you really want to do it your way, you will have to quote the whole path.
-Gary-
- 05-31-2010, 09:05 AM #13
Member
- Join Date
- May 2010
- Posts
- 5
- Rep Power
- 0
Similar Threads
-
running command prompt using java
By xclaim in forum New To JavaReplies: 1Last Post: 01-14-2010, 03:46 AM -
[SOLVED] Running java programs from the command prompt
By wiz0r in forum New To JavaReplies: 6Last Post: 04-20-2009, 04:34 AM -
Running applet from command prompt
By niteshwar.bhardwaj in forum Java 2DReplies: 1Last Post: 03-12-2009, 08:10 AM -
problems in running d command prompt commands
By postaholic066 in forum Advanced JavaReplies: 1Last Post: 09-10-2008, 03:47 PM -
Running eclipse java project on command prompt
By hnmapara in forum New To JavaReplies: 1Last Post: 07-09-2008, 08:29 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks