Maven:运行带有依赖关系的创建的Jar文件 [英] Maven: Running created Jar-File with depedencies

查看:109
本文介绍了Maven:运行带有依赖关系的创建的Jar文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了一个小小的Java命令行工具,例如,我想使用它运行该工具

I've written a little Java command line tool, that I want to run by (for example)

java -jar myJarFile.jar de.my.path.MainClass arg0 arg1 arg2

我正在使用Maven来构建jar文件和管理权限.现在我发现,Maven在Jar文件中不包含POM文件的行为.因此,当我运行jar文件时,会收到ClassNotFoundExceptions.但是要执行jar文件,我需要在类路径中添加这些库.

For building the jar-File and managing the depedencies I am using Maven. Now I found out, that Maven does not include the depedencies of the POM-File in the Jar-File. So, when I run my jar-file, I get ClassNotFoundExceptions.. But to execute my jar-file I need those libraries in the classpath.

如何使用Maven进行管理?

How can I manage this with Maven?

谢谢您的帮助!

推荐答案

将此Maven程序集插件放在pom.xml中:

Put this maven assembly plugin in your pom.xml:

    <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>de.my.path.MainClass</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>

这篇关于Maven:运行带有依赖关系的创建的Jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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