Maven - How to use an artifact from local folder?

Viewed 391

I have a pre-compiled artifact Framework-0.0.1-SNAPSHOT.jar located in \lib folder. In my maven I try to use and include that as below:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.heroic.backend</groupId>
    <artifactId>BackendHeroic</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>BackendHeroic</name>
    <dependencies>
        <dependency>
            <groupId>com.heroic.utilities</groupId>
            <artifactId>Framework</artifactId>
            <scope>compile</scope>
            <version>0.0.1-SNAPSHOT</version>
            <type>jar</type>
        </dependency>
    </dependencies>
    <properties>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>
</project>

But look like I cannot import anything in my code from that Framework jar file. Can you please let me know what's wrong with my setup above? Thank you

2 Answers

You can add a local repository:

<repositories>
    <repository>
        <id>local-libs</id>
        <name>Libs Local Repository</name>
        <url>file://${project.basedir}/lib</url>
    </repository>
</repositories>

Then you can add a dependency:

<dependencies>
    <dependency>
        <groupId>my.company</groupId>
        <artifactId>Framework</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
</dependencies>

But you need to put your jar file under /lib/my/company/0.0.1-SNAPSHOT/Framework-0.0.1-SNAPSHOT.jar

Maven looks in the Internet for dependencies, it does not inspect lib directory.

If this artifact built with maven in another project, just install it into your local repository cache: mvn install

If you just got this jar file from someone, install it with the following command:

mvn install:install-file -Dfile=Framework-0.0.1-SNAPSHOT.jar -DgroupId=com.heroic.utilities -DartifactId=Framework -Dversion=0.0.1-SNAPSHOT -Dpackaging=jar

you can write it into bat or sh script for other people.

Related