Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a maven created jar file using just the command line

Tags:

java

maven

jar

I need some help trying to run the following maven project using the command line: https://github.com/sarxos/webcam-capture, the webcam-capture-qrcode example is the one I'm trying to run. I have it running using an the Eciplse IDE but need to move it over to just using the command line. I have the jar's created by maven.

I'm trying

java -classpath ./webcam-capture/target/webcam-capture-0.3.10-SNAPSHOT.jar  com.github.sarxos.webcam.WebcamQRCodeExample       

but I keep getting the

Exception in thread "main" java.lang.NoClassDefFoundError: com/github/sarxos/webcam/WebcamQRCodeExample Caused by: java.lang.ClassNotFoundException: com.github.sarxos.webcam.WebcamQRCodeExample 
like image 845
Oujk Avatar asked Apr 08 '13 01:04

Oujk


People also ask

How do I run a maven program from the command line?

7. Running a Maven build via the command line. To build a Maven project via the command line, you use the mvn command from the command line. The command must be executed in the directory which contains the relevant pom file.


1 Answers

Just use the exec-maven-plugin.

<build>     <plugins>         <plugin>             <groupId>org.codehaus.mojo</groupId>             <artifactId>exec-maven-plugin</artifactId>             <version>1.2.1</version>             <configuration>                 <mainClass>com.example.Main</mainClass>             </configuration>         </plugin>     </plugins> </build> 

Then you run you program:

mvn exec:java 
like image 122
maba Avatar answered Sep 23 '22 12:09

maba