4

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

M. S.
  • 3,461
  • 10
  • 22
  • 33
Kiddo
  • 1,540
  • 7
  • 25
  • 50
  • Has that framework being built with Maven? – khmarbaise Mar 13 '20 at 16:07
  • @khmarbaise yes it was built using maven, and it was from another person from another team, but i can access that code if needed – Kiddo Mar 13 '20 at 16:10
  • 3
    Than either use a repository manager which will be filled via a CI solution or just clone the repo and do `mvn clean install` and afterwards use it as a usual dependency.. – khmarbaise Mar 13 '20 at 16:55
  • 2
    The canonical way to work with Maven artifacts across teams is to set up a company wide Maven repository like Artifactory or Nexus or the like; and have people deploy their artifacts there. Working with local repositories or `system` dependencies does not scale well (and is IMHO "working against the tools") – Gyro Gearless Mar 13 '20 at 16:55
  • @GyroGearless very good explained. Always the best solutions. And yes it's working against the tools. – khmarbaise Mar 13 '20 at 17:13

2 Answers2

1

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

M. S.
  • 3,461
  • 10
  • 22
  • 33
  • @Kiddo I just want to mention something, I don't know what IDE you're using but I did face some problems with some versions of Intellij before. They fixed the issue later. – M. S. Mar 13 '20 at 16:26
  • Im using Eclipse and this works for me so i think it should be fine, im on the latest 2019 version on eclipse – Kiddo Mar 13 '20 at 16:31
0

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.

vbezhenar
  • 8,347
  • 6
  • 40
  • 53