Reputation: 26437
What is the convention to store jar files inside maven project? I know that I should download jars using maven itself, but this time the case is different. I'm doing a course (coursera.org) and I've got somewhat secret jar file which I'm supposed to use and it's not public - I won't download it with maven. And I do want to store the .jar file in my private repo (bitbucket). The question is just where should I put the file, so that maven project will be able to use this jar.
Upvotes: 1
Views: 2887
Reputation: 183
Here is another simple way to do this: Create a file based maven repo inside the project directory
Pros: - Anyone can checkout the project and do a maven compile - No need to install a repository manager
Cons: - The jar will be in project directory
How to do this? I am including ojdbc6.jar in a project.
Step 1: Copy the ojdbc6.jar to ${project.baseDir}/lib/com/oracle/driver/ojdbc6/SNAPSHOT/ojdbc6-SNAPSHOT.jar
Step 2: Add the dependency in your pom
<dependency>
<groupId>com.oracle.driver</groupId>
<artifactId>ojdbc6</artifactId>
<version>SNAPSHOT</version>
</dependency>
Step 3: Add this to your pom. Here we are asking maven to consider the lib directory inside your project dir as a maven repo.
<repositories>
<repository>
<id>my-repo</id>
<name>mycustom repo</name>
<url>file:${project.basedir}/lib</url>
</repository>
</repositories>
Step 4: Analyse the path of the jar file in step 2. ${project.baseDir}/lib/com/oracle/driver/ojdbc6/SNAPSHOT/ojdbc6-SNAPSHOT.jar
We have stored the jar, very similar to how maven stores in a repo.
Upvotes: 3
Reputation: 97359
The best thing is to install a repository manager like Artifactory, Nexus, Archiva and store such files into the repository manager and use them as usual dependency.
Upvotes: 2
Reputation: 442
You need to add it to local repository. And then use it as any other jar.
You do it like this:
mvn install:install-file -Dfile={filename}.jar -DgroupId={some.group.id}
-DartifactId={artifact} -Dversion={version} -Dpackaging=jar
Then you use it like this:
<dependency>
<groupId>{some.group.id}</groupId>
<artifactId>{artifact} </artifactId>
<version>{version}</version>
</dependency>
Upvotes: 7