Re: Running java programs from class files



mark13.pl@xxxxxxxxx wrote:
Hello,

I have created two class: ClassOne & ClassTwo (with main) in MyClass
package. When I run it in eclipse everything goes okay. When I create
jar and choose ClassTwo as Main everything goes okay.
But now I am interested in running it just from class files. What is a
correct syntax for such example?!?
I tried:
"java -classpath . ClassTwo" and similar but never run it getting all
the time: NoClassDefFoundError.

Regards, mark


If your classes are in a package, then you must be in the directory above the package to run from class files. So if you package is called MyPackage, your class file is called MyClass.class and the MyPackage directory is located in /xyz/abc then you must be in /xyz/abc. To execute your program then you must type java MyPackage.MyClass.

--

Knute Johnson
email s/nospam/knute/
.



Relevant Pages

  • Re: Running java programs from class files
    ... ClassOne & ClassTwo in MyClass ... When I run it in eclipse everything goes okay. ... If your classes are in a package, then you must be in the directory ... execute your program then you must type java MyPackage.MyClass. ...
    (comp.lang.java.programmer)
  • Re: Running java programs from class files
    ... ClassOne & ClassTwo in MyClass ... When I run it in eclipse everything goes okay. ... If your classes are in a package, then you must be in the directory ... execute your program then you must type java MyPackage.MyClass. ...
    (comp.lang.java.programmer)
  • Re: Running java programs from class files
    ... ClassOne & ClassTwo in MyClass ... When I run it in eclipse everything goes okay. ... package names, tokenised along dots, e.g. java.lang.String would be in ... Whichever directory has the java directory (in ...
    (comp.lang.java.programmer)
  • Re: Class cant find another class in the same directory
    ... referring to the second class when I go to build it. ... If they belong to the same package there is no need to import anything. ... necessary class files relative to your current location. ... represented by the directory hierarchy my/path. ...
    (comp.lang.java.programmer)
  • Q: Java source and directory structure - standard way ?
    ... When I compile I use the -d option on Sun's SDK... ... and places the class files into it. ... Java source. ... code directory structure has been created to mirror the package names. ...
    (comp.lang.java)