[英]Add Jar and Classifier as dependency to Maven project
I have a local Jar file that I want to add as a dependency for a Maven project that I am working on. 我有一个本地Jar文件,要添加为我正在处理的Maven项目的依赖项。
That is easy to do as this answer states. 如该答案所述,这很容易做到。
The problem is that this Jar file requires a foo.classifier
file to work properly. 问题在于此Jar文件需要一个
foo.classifier
文件才能正常工作。
This Jar file is meant to be run by command line ( java -jar bar.jar {argument}
). 该Jar文件应通过命令行(
java -jar bar.jar {argument}
)运行。 The Jar and the classifier files are in the same directory, so everything works just fine. Jar和分类器文件位于同一目录中,因此一切正常。
However, from my project, I want to call the Jar file using its methods and not running a process. 但是,从我的项目中,我想使用其方法而不是运行进程来调用Jar文件。
I added the Jar file as a dependency and managed to call the main method that receives the argument, however, it doesn't work properly because of the foo.classifier
the file is not set as a dependency for that Jar file to work. 我将Jar文件添加为依赖项,并设法调用了接收参数的main方法,但是,由于
foo.classifier
文件未设置为该Jar文件起作用的依赖项,因此无法正常工作。
Does anyone know how can I set it as a dependency of that Jar file? 有谁知道如何将其设置为该Jar文件的依赖项?
将foo.classifier
文件放在.m2 \\ repository文件夹中的确切文件夹中,在其中您作为依赖项添加的本地Jar文件作为依赖项jar存在,将从本地存储库引用
您可以将jar放入libs目录,然后将以下代码添加到pom.xml文件中:
<dependency> <groupId>htmlunit</groupId> <artifactId>htmlunit</artifactId> <version>2.21-OSGi</version>`` <scope>system</scope> <systemPath>the full path of the jar</systemPath> </dependency>
Add the jar to maven repository with the follows command line, specify a group id, artifact id and a version 使用以下命令行将jar添加到Maven存储库,指定组ID,工件ID和版本
mvn install:install-file -Dfile="my-local.jar" -DgroupId="my.groupid" -DartifactId="name" -Dversion="1.0.0" -Dpackaging=jar
and then add as dependency to your pom 然后添加到您的pom依赖项
<dependency>
<groupId>my.groupid</groupId>
<artifactId>name</artifactId>
<version>1.0.0</version>
</dependency>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.