• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How To Set path of java in Windows 7

 
Amit K Srivastava
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12186
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49796
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49796
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You’re welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic