简体   繁体   English

将Jar和Classifier添加为对Maven项目的依赖

[英]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.

相关问题 如何将本地jar添加为maven项目的依赖项? - how to add a local jar as a dependency to a maven project? 如何在Maven多模块项目中添加test-jar和jar作为依赖项? - How to add test-jar and jar as dependency in a maven multimodule project? <Maven>如何在maven项目中将类文件添加为依赖项(而不是jar)? - <Maven>How to add class files as dependency (not jar) in maven project? 如何将本地项目(不是 jar)作为依赖项添加到 Maven 项目 - How to add local project (not jar) as a dependency to a Maven project 如何在另一个 maven 项目中添加 Maven 项目作为依赖项并对其进行实时更改而不是 JAR 依赖项 - How to add a Maven project as dependency in another maven project and make live changes to it instead of JAR dependency Eclipse-如何将一个项目作为Maven依赖项添加到另一个项目中,而不是作为一个jar添加? - Eclipse - How to add a project as a Maven dependency to another, instead of adding as a jar? 在Maven项目中为j2ee.jar添加依赖项 - Add dependency in maven project for j2ee.jar 导入到eclipse时,Maven不会将依赖jar文件添加到项目中 - Maven does not add dependency jar files to project when importing to eclipse Maven:通过项目目录外的相对路径向jar添加依赖项 - Maven: add a dependency to a jar by relative path outside the project directory 将jar添加到Maven项目 - Add jar into Maven project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM