Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add Maven dependency jar file from the lib folder

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?

like image 735
Rob Avatar asked Mar 19 '14 14:03

Rob


People also ask

How do I add a jar file to a Lib folder?

After you create a Java project, create a new folder by going to File > New > Folder. Call it “lib”. Then import the JAR file into the lib folder by going to File > Import > General > File. Alternatively, you could just copy the JAR file manually into that folder by navigating to it in your workspace.

How do I create a missing jar in Maven repository?

Look in your . m2 directory (use the paths which you see in the dialog above) and check whether the files are there or whether they are really missing. If they are missing, run "mvn install" (see the "Run as..." menu) to download them.

How do I add a dependency in Maven?

Add a Java Maven Dependency to the Utility ProjectRight-click the utility project, and select Maven>Add Dependency. Type a dependency name in the Enter groupID… field (e.g., commons-logging) to search for a dependency. Select the dependency, and click OK.


1 Answers

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.

like image 75
carlspring Avatar answered Nov 08 '22 18:11

carlspring