Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Java by (10.2k points)

How to add local jar files (not yet part of the Maven repository) directly in my project's library sources?

2 Answers

0 votes
by (46k points)

There are many ways to add local jar files to a Maven project:

1.Install manually the JAR into a local Maven repository

Use this plugin:

mvn install:install-file -Dfile=<path-to-file>

Example:

mvn install:install-file –Dfile=C:\dev\app.jar -DgroupId=com.roufid.tutorials -DartifactId=example-app -Dversion=1.0

Now, add the dependency to your Maven project by adding these lines to your pom.xml file:

<dependency>

    <groupId>com.roufid.tutorials</groupId>

    <artifactId>example-app</artifactId>

    <version>1.0</version>

</dependency>

2. Adding directly the dependency as system scope:

Consider that the JAR is located in <PROJECT_ROOT_FOLDER>/lib

After this add the dependency in your pom.xml file as following:

<dependency>

    <groupId>com.roufid.tutorials</groupId>

    <artifactId>example-app</artifactId>

    <version>1.0</version>

    <scope>system</scope>

    <systemPath>${basedir}/lib/yourJar.jar</systemPath>

</dependency>

3. Creating a different local Maven repository:

This one is quite similar to the first one, the only difference lies in the fact that the JARs will be installed in a different local Maven repository.

First, deploy the local JARs in the new local maven repository as below:

mvn deploy:deploy-file -Dfile=<path-to-file> -DgroupId=<group-id> 

After deploying the JARs you need to add the repository in your pom.xml file:

<repositories>

    <repository>

        <id>maven-repository</id>

        <url>file:///${project.basedir}/maven-repository</url>

    </repository>

</repositories>

After this add the dependency into your pom.xml

<dependency>

    <groupId>com.roufid.tutorials</groupId>

    <artifactId>example-app</artifactId>

    <version>1.0</version>

</dependency>

0 votes
ago by (1.9k points)

If you`re seeking to upload nearby JAR documents (now no longer but a part of a Maven repository) at once for your Java mission, here`s a brief manual for each Eclipse and IntelliJ IDEA users.

In Eclipse

  • Right-click your project, then select Properties.
  • Now go to Java Build Path followed by the Libraries tab.
  • Click Add External JARs, select the file you want to import from your local directory and then click OK.

In IntelliJ IDEA

  • Go to File > Project Structure
  • Click on Modules and navigate to the Dependencies tab.
  • Then click the + sign next to the JARs or directories. From this list, select the desired JAR files, and then click OK.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 11, 2019 in Java by Ritik (3.5k points)
0 votes
1 answer
0 votes
1 answer
asked Oct 17, 2019 in Java by Shubham (3.9k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...