Compiling and running a java program with a complex file structure from the command line


Trying to compile and run my java program from the commandline that is set up a bit weird. The file structure is as follows:

|    |____myExtraJar.jar

The package is defined at the top of the java file as

package com.example;

I am able to compile the program fine (I think) while in the root folder, using

javac -classpath "/libs/myExtraJar.jar" src/main/com/example/*.java

I don't get any compilation errors (such the ones that occur if I leave off the classpath) and I can see that .class files are being created in the com/example/ folder. However, I can't find any way to run the compiled program. Running

java src/main/com/example/myClass

results in the message

Error: Could not find or load main class

Any help would be appreciated.

You need to specify the classpath when you run it, and you also need to use the fully-qualified classname. Like,

java -cp "libs/myExtraJar.jar:src/main" com.example.myClass