File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes compile and run Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "compile and run " Watch "compile and run " New topic

compile and run

sweety sinha
Ranch Hand

Joined: Jul 07, 2008
Posts: 76
i am stuck

suppose i have created my file in "C:\Program Files\IBM\jprog" named now i compile it on Dos prompt giving command c:\>javac "program files\ibm\jprog\". then compilation is ok
class file is also created. but when i tried to run it from c:\>java "program files\ibm\jprog\primary" and
c:\program files>java ibm\jprog\primary it is not running and giving
C:\>java "program files\ibm\jprog\primary"
Exception in thread "main" java.lang.NoClassDefFoundError: program files\ibm\jpr
og\primary (wrong name: primary)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(
at Method)
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
at java.lang.ClassLoader.loadClassInternal(

please help me in this. how can we run from different folder

thanks in advance
Pranav Bhatt
Ranch Hand

Joined: Mar 20, 2006
Posts: 284
When you are using javac there is .java at end which DOS can see as a file and so it works out, but while you run it you don't give .java extension to your file so its considering it as a dir name itself. You can try this to run it-:

C:\>java -cp "program files\ibm\jprog" primary

Check it out

Note- Here cp stands for classpath, you can check what all option you can use by simply giving java and javac commands in DOS.

[ September 06, 2008: Message edited by: Pranav Bhatt ]
Ashish Hareet
Ranch Hand

Joined: Jul 14, 2001
Posts: 375
You need to set the classpath. Try using the following command

You may also want to look at the java & javac references
javac -
java -

Ashish Hareet
[ September 06, 2008: Message edited by: Ashish Hareet ]
sweety sinha
Ranch Hand

Joined: Jul 07, 2008
Posts: 76
thanks Pranav & Ashish for the quick response.
I agree. Here's the link:
subject: compile and run
jQuery in Action, 3rd edition