Java Fully Qualified Class name, running from Terminal -
please excuse confusion, have searched topic on stack overflow not understand answers. green. using eclipse create first java program, compiles , runs successfully.
package com.java24hours; class saluton { public static void main (string[] arguments) { //my first java program goes here string greeting = "saluton mondo!"; system.out.println(greeting); } }
so trying run in terminal on mac. file path have /users/admin/documents/java/java24/com/java24hours
i try run in java24hours directory "java saluton.java" , return "error: not find or load main class saluton.java"
it understanding has package. have researched package names not understand how qualified name works classes , packages.
while compiles in ide, make compile in terminal , understand why did not compile way wanted to.
thank patience.
you missing several elements.
one answer , comment pointed out haven't compiled source code yet, produce class file. that's absolutely correct. eclipse on own, , puts class files in "bin" directory, although i'm not sure parent folder be, perhaps "/users/admin/documents/java".
to compile , execute classes command line, outside of eclipse, it's best have "build script" builds class files , optionally runs classes. utilize "gradle" or "maven", or perhaps "ant" (in decreasing order of preference).
in case, when execute class command line, have tell java process "classpath" use, , name of "fully-qualified" class name execute.
so, if had class files written in "/users/admin/documents/java/bin" directory, might running "/users/admin/documents/java" directory, , execute following:
java -cp bin com.java24hours.saluton
Comments
Post a Comment