Maven:运行命令行应用程序时使用存储库中的依赖项? [英] Maven: use dependencies from repository when running command line app?

查看:120
本文介绍了Maven:运行命令行应用程序时使用存储库中的依赖项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Maven构建了我的命令行应用程序.现在,我将其作为jar文件分发,并且需要处理应用程序的依赖项.

I've used Maven to build my command line application. Now I'm going to distribute it as a jar file, and I need to handle the app's dependencies.

我不想按照运行我的应用程序的环境为Maven.我希望Maven运行我的jar,查看包中的文件META-INF/groupId/artifactId/pom.xml,以便它知道依赖项是什么,并可以在存储库中找到它们.

The environment where my app will be run has Maven. I'd like Maven to run my jar looking at file META-INF/groupId/artifactId/pom.xml inside the package so it knows what the dependencies are and can find them in the repository.

有什么想法吗?

推荐答案

在jar中包含一个主类,该主类包括1)将pom提取到临时文件,以及2)使用带有-f的该文件启动新的maven进程.参数和目标 dependency:resolve dependency:build-classpath

Include a main class in the jar that 1) extracts the pom to a temporary file, and 2) launches a new maven process using this file with the -f parameter and the goals dependency:resolve and dependency:build-classpath

像这样:

mvn -f /temp/tempfile.xml dependency:resolve dependency:build-classpath -DoutputFile=/temp/classpath.txt

然后3)读取新创建的类路径文件,然后4)使用新的类路径文件启动新的Java进程

then 3) reads the newly created classpath file and 4) launches a new java process using the new classpath file

java -cp yourjar.jar;<created classpath>

您的pom.xml当然必须包含所有必需的存储库信息

Your pom.xml will have to include all required repository information, of course

这篇关于Maven:运行命令行应用程序时使用存储库中的依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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