Forums Register Login

compile and run

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
thanks Pranav & Ashish for the quick response.
Would you like to try a free sample? Today we are featuring tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 964 times.
Similar Threads
Difficulty in executing
path variable
XMLbeans giving problem with WebSphere
Package Issue / Class Path issue
Starting Websphere 6.0 in Eclipse3.3
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 02:07:44.