• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

How to run a class file from dir above or under it

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the A.java in test\woo\com\src dir

import java.util.Properties;

public class A {
public static void main(String[] args)
{
Properties p = System.getProperties();
p.setProperty("sdsd sdfs", "dsfs sdfs");
p.list(System.out);
}

}

javac ..\A.java

is used to compile it from the test\woo\com\src\classes dir. The A.class is in the test\woo\com\src as expected.
It seems no matter how do I use the -cp the in java command line from test\woo\com\src\classes, it always throws NoClassDefFoundError. Would anyone shed some light on this? Thanks!
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am able to execute the above referenced program from a directory under it as well from a directory above it. I think there might be some syntax error on the command line when you are trying at your end. Following are the commands which I executed.

java -cp ..\ A (This is from the test\woo\com\src\classes dir)



java -cp src A (This is from the test\woo\com dir)



Following is a snippet of the output from the program

-- listing properties --
java.runtime.name=Java(TM) SE Runtime Environment
sun.boot.library.path=C:\Program Files\Java\jre6\bin
java.vm.version=19.1-b02
sdsd sdfs=dsfs sdfs
java.vm.vendor=Sun Microsystems Inc.
java.vendor.url=http://java.sun.com/
path.separator=;
java.vm.name=Java HotSpot(TM) Client VM
file.encoding.pkg=sun.io



Hope this helps !

Thanks,
Hemnath
 
reply
    Bookmark Topic Watch Topic
  • New Topic