aspose file tools*
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
Author

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 primary.java. now i compile it on Dos prompt giving command c:\>javac "program files\ibm\jprog\primarya.java". 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(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
4)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

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
Sweety,
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 - http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/javac.htm
java - http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/java.html

HTH
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: http://aspose.com/file-tools
 
subject: compile and run
 
Similar Threads
XMLbeans giving problem with WebSphere
Starting Websphere 6.0 in Eclipse3.3
Difficulty in executing
path variable
Package Issue / Class Path issue