简体   繁体   English

Maven外部jar依赖

[英]maven external jar dependency

I am trying to use a jar given by my teacher in my code. 我正在尝试使用代码中老师给我的罐子。 So I placed the jar in a lib directory in my project and ran this command : 所以我将jar放在项目的lib目录中,并运行以下命令:

mvn install:install-file -Dfile=lib/IDLogger.jar -DgroupId=IDLogger -DartifactId=IDLogger -Dversion=1.0 -Dpackaging=jar

Everything is fine. 一切顺利。

Then I add the dependency to the pom : 然后我将依赖项添加到pom中:

<dependency>
   <groupId>IDLogger</groupId>
   <artifactId>IDLogger</artifactId>
   <version>1.0</version>
   <scope>compile</scope>
</dependency>

But then when I try to use the jar, the compilation fails and tells me that the symbol(the class) can't be found. 但是当我尝试使用jar时,编译失败并告诉我找不到该符号(该类)。 I even tried adding an import statement : 我什至尝试添加import语句:

import IDLogger.IDLogger;

but it tells me that there is no such package. 但是它告诉我没有这样的软件包。

How can I use this jar in my code in maven? 我如何在Maven的代码中使用此jar?

This is the code : 这是代码:

IDLogger logger = IDLogger.getInstance(); 

...

logger.logID(id); 

I get the symbol IDLogger not found error 我得到符号IDLogger找不到错误

This is as much as I know about this custom jar... 据我对这个定制罐子的了解...

Try to add your lib in system scope : 尝试在系统范围内添加您的库:

1. add in your project :

    Your Project/lib 
                +IDLogger.jar

2. in your pom :

     <dependency>
       <groupId>IDLogger</groupId>
       <artifactId>IDLogger</artifactId>
       <version>1.0</version>
       <scope>system</scope>
        <systemPath>${project.basedir}/lib/IDLogger.jar</systemPath>
     </dependency>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM