如何仅使用命令行运行 Maven 创建的 jar 文件 [英] How to run a maven created jar file using just the command line

查看:37
本文介绍了如何仅使用命令行运行 Maven 创建的 jar 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助来尝试使用命令行运行以下 Maven 项目:https://github.com/sarxos/webcam-capture,webcam-capture-qrcode 示例是我的示例我想跑.我使用 Eciplse IDE 运行它,但需要将其移至仅使用命令行.我有 maven 创建的罐子.

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.

我正在努力

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

但我一直收到

Exception in thread "main" java.lang.NoClassDefFoundError: com/github/sarxos/webcam/WebcamQRCodeExample
Caused by: java.lang.ClassNotFoundException: com.github.sarxos.webcam.WebcamQRCodeExample

推荐答案

只需使用 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>

然后你运行你的程序:

mvn exec:java

这篇关于如何仅使用命令行运行 Maven 创建的 jar 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆