In root directory:
javac -d target/classes src/main/java/app/Main.java src/main/java/util/Second.java
(-d option to set output dir)
Or javac -cp src/main/java/ src/main/java/app/Main.java
Assume there is a source code file (src/main/java/app/Main.java):
package app;
import util.Second;
public class Main {
public static void main(String[] args) {
System.out.println("inside test main");
new Second().mtd();
}
}
And second file is (src/main/java/util/Second.java):
package util;
public class Second {
public void mtd () {
System.out.println("inside Second");
}
}
And Main.class placed in /target/classes/app (Maven structure).
So in order to run you have to use this command:
java -cp target/classes/ app.Main
in target folder after packaging project into jar:
java -cp my-test-1.0-SNAPSHOT.jar app.Main
runs main class
Another way:
java -jar myCopy.jar
but here you need to specify MANIFEST.MF:
Manifest-version: 1.0 Main-Class: Test
and create jar: jar cfm MyJar.jar ../MANIFEST.MF app/*.class util/*.class
More on jars: docs