Steerpike
Steerpike

Reputation: 1843

Use a locally stored .jar file as a dependency in a Maven project: compile class files

I'm a relative Maven novice and am having difficulties using a locally stored jar as a module within my IntelliJ project - a project I have taken from an online tutorial.

I've brought it into my .m2 folder using:

mvn install:install-file "-Dfile=C:/../resources/myshop-automatedtestscore 3.1.17-SNAPSHOT.jar" "-DpomFile=C:/../resources/myshop-automatedtestscore-3.1.17-SNAPSHOT.pom --Dsources=C:/../myshop-automatedtestscore-3.1.17-SNAPSHOT-sources.jar"

.jar is located at:

C:\Users\daveb\.m2\repository\com\myshop\automatedtests\myshop-automatedtestscore\3.1.7-SNAPSHOT\3.1.17-SNAPSHOT.jar

And I added the dependency in the main pom.xml as follows:

<dependency>
      <groupId>com.myshop.automatedtests</groupId>
      <artifactId>myshop-automatedtestscore</artifactId>
      <version>3.1.17-SNAPSHOT</version>
</dependency>

When I go to Project Structure -> Libraries, I can see the Sources dependency jar file is there in grey so should be fine. However the core project seems to be unable to access the class versions of the file. In Target folder they remain .class but in External libraries they are .java

enter image description here

Apologies if this is a novice or obvious solution. I'm trying to resolve.

Upvotes: 1

Views: 537

Answers (3)

Andy Sug
Andy Sug

Reputation: 244

If your dependency is

<groupId>com.me.example</groupId>
<artifactId>my-example</artifactId>
<version>1.1.0</version>

Then your jar file would be my-example-1.1.0.jar and it will be under \.m2\repository\com\me\example\my-example\1.1.0\my-example-1.1.0.jar.

In your case, your jar file is myshop-automatedtestscore-3.1.17-SNAPSHOT.jar and it should be under

C:\Users\daveb.m2\repository\com\myshop\automatedtests\myshop-automatedtestscore\3.1.17-SNAPSHOT\myshop-automatedtestscore-3.1.17-SNAPSHOT.jar.

After this, do a Maven > Reimport from IntelliJ.

Upvotes: 0

Sorin Penteleiciuc
Sorin Penteleiciuc

Reputation: 865

You can press here to force refresh the plugins in Intelij.

Refresh

Here you can check which repository you have and also which maven you have. Maven settings Click on preferences

Another option you have is to perform this :

mvn clean install -U

Upvotes: 1

Pinki Sharma
Pinki Sharma

Reputation: 143

You have to install jar using below command -

mvn install:install-file -Dfile= -DgroupId= -DartifactId= -Dversion= -Dpackaging=

You have to give artifacts and other parameters so that you will be able to use in pom file using below code -

<dependency>
   <groupId>org.jboss.resteasy</groupId>
   <artifactId>resteasy-jackson-provider</artifactId>
   <version>1.1.GA</version>
</dependency>

After that you have to complie your project so that this dependency will be added in your project.

mvn eclipse:eclipse mvn clean install

Upvotes: 1

Related Questions