• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Java file is not getting executed  RSS feed

 
Ranch Hand
Posts: 386
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to this environment and trying to test java code, it seems some settings are not working.

Where is java executable located ? I have tried using it in different locations (I can see java in bin folder at different locations , like in jdk, jre and jre within jdk). I am unable to attach screen shots. Please let me know which is correct one and how does its logo look ?
Source code and compiled clas file are located in same location (C:\Users\nm2t\Desktop\TestJava). Source code is compiling fine, but when I am running this class file, I am getting
Following java file is executed from "C:\Program Files\java\jre1.6.0_41\bin"

C:\Program Files\java\jre1.6.0_41\bin>java C:\Users\nm2t\Desktop\TestJava\TestForTS
Exception in thread "main" java.lang.NoClassDefFoundError: C:\Users\nm2t\Desktop\TestJava\TestForTS
Caused by: java.lang.ClassNotFoundException: C:\Users\nm2t\Desktop\TestJava\TestForTS
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)
Could not find the main class: C:\Users\nm2t\Desktop\TestJava\TestForTS. Program will exit.

Following java file is executed from Java path variable set in system variable. Path variable is set as PATH = C:\Program Files\java\jdk1.6.0_25\bin;

C:\Program Files>java C:\Users\nm2t\Desktop\TestJava\TestForTS
Exception in thread "main" java.lang.NoClassDefFoundError: C:\Users\nm2t\Desktop\TestJava\TestForTS
Caused by: java.lang.ClassNotFoundException: C:\Users\nm2t\Desktop\TestJava\TestForTS
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:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: C:\Users\nm2t\Desktop\TestJava\TestForTS. Program will exit

Below is the output for PATH variableC:\Program Files\java\jdk1.6.0_25\jre\bin>echo %PATH%
C:\Program Files\Support Tools\;C:\Program Files (x86)\Common Files\Interwoven\lib;D:\iw-home\TeamSite\bin;D:\iw-home\TeamSite\iw-perl\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;c:\oracle32\ora112\bin;C:\PROGRA~2\MKSTOO~1\bin64;C:\PROGRA~2\MKSTOO~1\bin;C:\PROGRA~2\MKSTOO~1\bin\X11;C:\PROGRA~2\MKSTOO~1\mksnt;D:\iw-home\OpenDeployNG\bin;D:\ctmag\Default\EXE\;C:\Program Files\System Center Operations Manager 2007\;
C:\Program Files\Microsoft Network Monitor 3\;C:\Program Files\Microsoft Windows Performance Toolkit\;C:\oracle32\ora112\bin;
C:\Program Files\java\jdk1.6.0_25\bin;D:\ctmag\Default\exe

Following java file is executed from "C:\Program Files\java\jdk1.6.0_25\jre\bin"

C:\Program Files\java\jdk1.6.0_25\jre\bin>java C:\Users\nm2t\Desktop\TestJava\TestForTS
Exception in thread "main" java.lang.NoClassDefFoundError: C:\Users\nm2t\Desktop\TestJava\TestForTS
Caused by: java.lang.ClassNotFoundException: C:\Users\nm2t\Desktop\TestJava\TestForTS
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:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: C:\Users\nm2t\Desktop\TestJava\TestForTS. Program will exit.


Following java file is executed from "C:\Program Files\java\jdk1.6.0_25\bin"

C:\Program Files\java\jdk1.6.0_25\bin>java C:\Users\nm2t\Desktop\TestJava\TestForTS
Exception in thread "main" java.lang.NoClassDefFoundError: C:\Users\nm2t\Desktop\TestJava\TestForTS
Caused by: java.lang.ClassNotFoundException: C:\Users\nm2t\Desktop\TestJava\TestForTS
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:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: C:\Users\nm2t\Desktop\TestJava\TestForTS. Program will exit.

Whats going on over here ? Why is TestForTS.class is not getting executed ?

Thanks
 
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The java command takes a class name as parameter, not a file name. If the class is not in the current directory, you'd use a classpath to point the JVM to it. Somewhat like this:

java -cp C:\Users\nm2t\Desktop\TestJava TestForTS

Also note that the PATH is different from the CLASSPATH (so the PATH you posted is irrelevant).
 
nirjari patel
Ranch Hand
Posts: 386
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Following is output with executing as "C:\Program Files\java\jre1.6.0_41\bin>java -cp C:\Users\nm2t\Desktop\TestJava\TestForTS"
Can I use any java.exe ? either from "C:\Program Files\java\jre1.6.0_41\bin" OR from "C:\Program Files\java\jdk1.6.0_25\bin" OR from "C:\Program Files\java\jdk1.6.0_25\jre\bin" ?

C:\Program Files\java\jre1.6.0_41\bin>java -cp C:\Users\nm2t\Desktop\TestJava\TestForTS
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)

where options include:
-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is client.

-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose[:class|gc|jni]
enable verbose output
-version print product version and exit
-version:<value>
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -jre-no-restrict-search
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument

-splash:<imagepath>
show splash screen with specified image

 
author
Sheriff
Posts: 23589
138
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

nirjari patel wrote:Following is output with executing as "C:\Program Files\java\jre1.6.0_41\bin>java -cp C:\Users\nm2t\Desktop\TestJava\TestForTS"
Can I use any java.exe ? either from "C:\Program Files\java\jre1.6.0_41\bin" OR from "C:\Program Files\java\jdk1.6.0_25\bin" OR from "C:\Program Files\java\jdk1.6.0_25\jre\bin" ?

C:\Program Files\java\jre1.6.0_41\bin>java -cp C:\Users\nm2t\Desktop\TestJava\TestForTS
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)



That message is the help/usage page. The JVM prints it when the command is not valid. Perhaps the Oracle tutorial is a good starting place... as learning by forum is not really efficient here...

http://docs.oracle.com/javase/tutorial/getStarted/index.html

Henry
 
Ulf Dittmer
Rancher
Posts: 42975
76
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

nirjari patel wrote:Following is output with executing as "C:\Program Files\java\jre1.6.0_41\bin>java -cp C:\Users\nm2t\Desktop\TestJava\TestForTS"


That's not what I said to try. Programming is all about paying attention to detail.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!