aspose file tools*
The moose likes Java in General and the fly likes How To Set path of java in Windows 7 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How To Set path of java in Windows 7" Watch "How To Set path of java in Windows 7" New topic
Author

How To Set path of java in Windows 7

Amit K Srivastava
Greenhorn

Joined: May 31, 2012
Posts: 7
Hello Sir,
When i am running this program in my system , it compile fine but on run it gives following errors .I am not able to run this file.While it successfully run in NetBeans i am using in my system.I am not getting what is reason for this.Please help me.In fact i have installed this many times but it worthless.Here i am showing console output below.This is Simple Hello World Example.





I:\>javac Hello.java

I:\>java Hello
Exception in thread "main" java.lang.NoClassDefFoundError: Hello
Caused by: java.lang.ClassNotFoundException: Hello
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: Hello. Program will exit.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11314
    
  16

the problem is not with your path, but your classpath. it probably doesn't contain the local directory. a short term solution would be to do this:

java -cp . Hello

Try that, and see if it works.

Note: This assumes that you are in the same directory with the Hello.class file.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38851
    
  23
Welcome to the Ranch

Please avoid coloured text; I have changed it to black because many people can’t read red.
That isn’t a path problem at all. Please verify that the Hello.java and Hello.class files are in your current directory, with the dir command. If the files are in your current directory, read on.
What have you done with your classpath? Have you set a system classpath? That usually does more harm than good, and is a common cause of your problem. If you have set your own system classpath, delete it. All of it.
If you didn’t set a classpath, add .; dot‑semicolon at the beginning of your classpath.
Amit K Srivastava
Greenhorn

Joined: May 31, 2012
Posts: 7
thank you so much Sir Campbell Ritchie:
It works !.
I had set Apache Tomcat Path as classpath in both user and system varaible , that was creating problem.And in future i want put any query in colors as you mentioned.
Thank You So Much.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38851
    
  23
You’re welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How To Set path of java in Windows 7