I following this post and this post to build an java app.
Here is all the content in my company/HelloWorld.java
package company;
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World");
}
}
Classically, running a java program needs 2 steps:
- javac the file, for example
javac company/HelloWorld.java
- java the class file, for example
java company.HelloWorld
which gave me "Hello, World", as expected.
It seems java -cp
could do the 2 steps above in a batch, although it seems that my env does not recognize this command
java -cp company.HelloWorld
and outputs
Usage: java [-options] class [args...]
this is another version, according to @hayrettinm's answer.
package company.HelloWorld;
didn't work either. what am I missing?
Why do I thought java -cp
could do compile and run? this post gives this example
PS C:\Lecture_java\Lecture001\Hello> & 'C:\Users\ubuntu\.vscode\extensions\vscjava.vscode-java-debug-0.23.0\scripts\launcher.bat' 'C:\Program Files\Java\jdk-13.0.1\bin\java' '-Dfile.encoding=UTF-8' '-cp' 'C:\Lecture_java\Lecture001\Hello\bin' 'app.App'
after the experiment, I guess java -cp company.HelloWorld
could not compile and run, it just run an java application. Could someone give a
double confirmation.