Maven:运行命令行应用程序时使用存储库中的依赖项? [英] Maven: use dependencies from repository when running command line app?
问题描述
我已经使用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.
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屋!