Is it possible to run Java program from command li

2019-08-04 10:24发布

问题:

I have a set of instructions to create a Java application that takes multiple arguments when running the application from a CMD line.

The instructions state:

Thus, using the example set of above, assuming the main() method of your program is in a class called JavaClassName, the output should be:

$ java JavaClassName 4 7 file.csv
program output here

My question is:

Isn't this skipping the compile process?
Would they assume that loading the Java classes onto a computer that has never run this application before (or a directory with purely the .java files needed to run); running the cmd

$ java JavaClassName 4 7 file.csv

would output something?

Sidenote: Currently, running that CMD outputs

Error: Could not find or load main class JavaClassName

Have ran through multiple SO questions and online tutorials trying to get this to even run but I have yet to get it to work.

回答1:

You ask:

Isn't this skipping the compile process?

Absolutely yes. A command line like java JavaClassName 4 7 file.csv assumes that there is a compiled class file "JavaClassName.class" in the current directory (or in some other directory or Zip/Jar file found in the CLASSPATH environment variable). And yes, to produce that "JavaClassName.class" class file, you have to use a java compiler first.



标签: java cmd