Knute Johnson wrote:
mark13.pl@gmail.com 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.
Not 100% correct - though that is indeed the easiest way to do it. One
could actually be in any working directory as long as your commandline
while executing the "java" command also includes a -classpath argument
that points to the base of your package hierarchy.,
The commandline for the above example in that case would be :
java -classpath /xyz/abc MyPackage.MyClass
BK
like that. Could it be that it doesn't work on Windows like that?