I am trying to run my first Java program, an example script that interacts with a online API (source on Github).
As it has dependencies, I follow the recommended steps using mvn test
and mvn package
, which seem to work (see output).
I however do not understand how to run the program that I just compiled (or packaged?). The .java
file contains public final class NesstarStudyLister
, so based on the pom.xml
file I try (in the base directory) the following command:
mhermans@fyr:~/tmp/nesstar-api-demo$ java -cp target/nesstar_study_lister-1.0-SNAPSHOT.jar com.nesstar.demo.NesstarStudyLister
Which results in a NoClassDefFoundError
.
How can I successfully run the small Java-program?
EDIT:
Based on the recommendation of Dave Newton, I used the Exec Maven plugin, which apparently simply consists of running
mvn exec:java -Dexec.mainClass=com.nesstar.demo.NesstarStudyLister
in the base directory, which flawlessly executes the java program.
The solution by Andriy Plokhotnyuk also works, using these commands:
(edit pom.xml to include the <build>...</build> information)
mvn package
java -jar target/nesstar_study_lister-1.0-SNAPSHOT-jar-with-dependencies.jar