문제

I am trying to add a jar file to the Maven dependency in my project. The settings.xml is configured to set the repository to a public repository. But this particular jar is not present in that repo. As i have the jar in my lib folder, how can i configure the Maven dependency to take this jar?

도움이 되었습니까?

해결책

Have a look at system dependencies.

You basically need to define <scope>system</scope>.

<project>
    ...
    <dependencies>
      <dependency>
        <groupId>javax.sql</groupId>
        <artifactId>jdbc-stdext</artifactId>
        <version>2.0</version>
        <scope>system</scope>
        <systemPath>${java.home}/lib/rt.jar</systemPath>
      </dependency>
    </dependencies>
    ...
</project>

This is if you don't have your own hosted artifact repository server such as Nexus, Artifactory or Archiva.

If you do, then as Karl-Heinz suggested, you would be better off placing it there, as it's not good practice to commit binary artifacts to version control.

다른 팁

Another option is to set up a repository that is backed by a directory inside your project, per this answer: https://stackoverflow.com/a/2230464/433789

Changing pom.xml worked for me (jar in "/lib" directory in the root project folder) :

    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.6</version>
        <scope>system</scope>
        <systemPath>${project.basedir}/lib/gson-2.8.6.jar</systemPath>
    </dependency>

The best solution is to start using a repository manager like Nexus and put it there. Or you can use the non-maven-jar-plugin.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top