Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Class path

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the following set in my unix path and classpath
PATH=/ora/pofd/pofddb/8.1.7/xdk/java/parser/bin/:/ora/pofd/pofddb/8.1.7/xdk/lib/
:/ora/pofd/pofddb/8.1.7/lib/:/ora/pofd/pofddb/8.1.7/xdk/bin/:/ora/pofd/pofdcomn/
util/jre/1.1.8/lib/:/ora/pofd/pofdcomn/util/jre/1.1.8/bin:/usr/java131/jre/lib:/
usr/java131/lib:/usr/java131/bin:/usr/bin:/etc:/usr/sbin:/usr/ucb:$HOME/bin:/usr
/bin/X11:/sbin:/bin:/work/scripts:/usr/ibmcxx/bin:/work/vsubra/fullsaxon:.
export PATH
CLASSPATH=/ora/pofd/pofdcomn/util/jre/1.1.8/libi18n.jar:/ora/pofd/pofdcomn/java/
xmlparserv2.zip:/work/vsubra/fullsaxon/saxon.jar:/work/vsubra/fullsaxon/saxon-fo
p.jar:/usr/java131/jre/lib/rt.jar:/usr/java131/lib/tools.jar:.
export CLASSPATH

when i create a file A.java while running it with java A
it gives me the following error:
Exception in thread "main" java.lang.noclass defn found.
I have given rt.jar in my path. What am I missing?
Thanks,
Vidhya
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not sure where to start based on your question....but here is a shot. First off, you know you must compile the A.java file to create a A.class file. Use the javac command to do this. Once you have created A.class, you execute this by typing java A (assuming you are not specifing a package). At the execution point, you must have the directory containing A.class on your classpath. Since you have . on your classpath, you can execute the java command from the directory containing A.class and everything should work.
Hope this helps.
 
vidhya subramaniam
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am in my root directory /work/vsubra. I have file A.java in this directory. When I compile useing javac A.java it does create a class in the same dir as A.class. But when I run it using java A then it gives me this error
Exception in thread "main" java.lang.NoClassDefFound error
i have given the path in my classpath also for rt.jar. The path goes as
/usr/java131/jre/lib/rt.jar;.
Why this error then?
Thanks,
Vidhya
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Do u use package in u'r Java program? If u use package, then u have to set that in u'r CLASSPATH, or else set the CLASSPATH=.;
----------
Nayan
 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if you have used a 'package' line in your program, e.g.
package com;
public class A{
// ...
}
and your 'A.java' is in '/work/vsubra', your file compiles but will not run.
You should create the package directory '/work/vsubra/com' (i.e. depending on the name of your package) and place your A.class file at '/com',
then run 'java com.A in '/work/vsubra'
check also if you have a 'main' method of the right signature.
hope this helps.
 
Chris Hall
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The reason for the NoClassDefFoundError is that it can't find your Class. With . on you classpath, you must make sure you are in the same directory as A.class when executing the 'java A' command. If you specified a package, refer to the previous post as to how to execute the java command and where to make sure your A.class is located.
At this point we can't tell if there is anything wrong with the actual code, since the error states it can't find it.
 
Men call me Jim. Women look past me to this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic