In Maven if you are trying to run the application in the CLI, you may have to add the maven-assembly-plugin
plugin like below. This plugin will help package all the dependencies in the same target jar file.
NOTE - To update the main class and package name in the <mainclass>
tag.
<!-- Add the assemble plugin with standard configuration -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.mycompany.app.App</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
You can then compile using maven like below to force the dependencies in the same target jar file.
$mvn clean compile assembly:single
This will add -jar-with-dependencies
to the jar file.
To run the built application, you can now do.
java -cp target/my-app-1.0-SNAPSHOT-jar-with-dependencies.jar com.mycompany.app.App arg1 arg2
PS - Thanks to this
for the answer, which is in almost the end.