Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a .class file in Windows 7 OS?

This is probably a stupid question, but how do I run a class file on windows 7? I usually create my own .java files and then use a basic IDE (with JDK6) to compile it to a class and run it automatically. My professor gave a .class file that we are supposed to play with extensively but I have no idea how to to run it here. Note that I cannot run it by typing:

java classname.class

because it contains gui stuff especially buttons and such. If I do the above I get the following error:

java.lang.NoClassDefFoundError: Test1/2/class
Caused by: java.lang.ClassNotFoundException: Test1.2.class
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: Test1.2.class.  Program will exit.
Exception in thread "main" 

Any help would be highly appreciated. Thanks.

like image 367
jNoob Avatar asked Jan 23 '26 04:01

jNoob


2 Answers

When you run it, don't include the .class suffix:

java classname
like image 187
Dean Harding Avatar answered Jan 24 '26 21:01

Dean Harding


In addition to the above, it should also make no odds what your O/S is. Java compiles to byte code, which is interpreted by your JVM. You clearly have one installed since you got the java error you have pasted above.

like image 30
Matt Avatar answered Jan 24 '26 20:01

Matt