0

I am using maven 3.2.5. I have one external jars which I need to use in my maven project which is not available in maven repository.

I installed those jars by using following command:

1) mvn install:install-file -Dfile=p-unit-0.15.319.jar -DgroupId=org.punit -DartifactId=p-unit -Dversion=0.15.319 -Dpackaging=jar

2) After this command, I saw in my M2 repository, jar & pom was created .m2\repository\org\punit\p-unit\0.15.319\p-unit-0.15.319.jar .m2\repository\org\punit\p-unit\0.15.319\p-unit-0.15.319.pom

created pom content:

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.punit</groupId>
  <artifactId>p-unit</artifactId>
  <version>0.15.319</version>
  <description>POM was created from install:install-file</description>
</project>

3) Updated the pom file

<dependency>
  <groupId>org.punit</groupId>
  <artifactId>p-unit</artifactId>
  <version>0.15.319</version>   
  <scope>provided</scope>                                         
</dependency>

Issue: When I tried to use class of this jar,

 import org.punit.runner.*;
 getting error: import org.punit.runner can't be resolved.

I tried many combination to define the dependency but not able to use the classes.

How can I resolve it??

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Manish
  • 81
  • 1
  • 7
  • what jar do you need to use? – Naman May 22 '16 at 11:26
  • please share your entire pom.xml – Naman May 22 '16 at 11:32
  • http://stackoverflow.com/questions/15105556/the-import-org-junit-cannot-be-resolved something similar should help – Naman May 22 '16 at 11:34
  • You should most probably remove `provided`. But your question isn't clear: what do you mean by *When I tried to use class of this jar*? – Tunaki May 22 '16 at 11:35
  • After removing the "scope" also it's not able to resolve. When I tried to use class of this jar? I mean, I am trying to import runner package which is in p-unit-0.15.319.jar(which I installed in my local repo). – Manish May 22 '16 at 11:46
  • Thanks nullpointer, .. your link has solved my issue.. – Manish May 22 '16 at 11:59

2 Answers2

0

Add the corresponding dependency to the pom.xml file of your project under the tag dependencies.

Example :

<dependencies>
    <dependency>
      <groupId>org.punit</groupId>
      <artifactId>p-unit</artifactId>
      <version>0.15.319</version>   
      <scope>test</scope>
    </dependency>
</dependencies>

Note : assuming the group,artifact ids and version are correct as mentioned in the question.

Naman
  • 27,789
  • 26
  • 218
  • 353
  • I have added corresponding dependency in my pom also. but still its not able to resolve the class. – Manish May 22 '16 at 11:33
  • Yes its correct only... I have pasted my install command and the dependency part also... Is there any other thing which may cause this issue? – Manish May 22 '16 at 11:37
0

One thing which I missed, I am mentioning here, which solved this issue. I had put the dependency in wrong profile which was not called during my compilation. When I put in correct profile it worked.

Second option:

We can directly add external jar through eclipse:

Properties -> Java Build Path -> Libraries -> Add External Jars.

and locate the library on the file system.

Answer to similar query: The import org.junit cannot be resolved

Community
  • 1
  • 1
Manish
  • 81
  • 1
  • 7