简体   繁体   中英

maven - where to store external jar files if needed

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.

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>

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

  • com/oracle/driver/ -- groupId (must be 3 components)
  • ojdbc6/ -- artifactId
  • SNAPSHOT/ -- verison

We have stored the jar, very similar to how maven stores in a repo.

最好的办法是安装一个 Artifactory,Nexus,Archiva之类的存储库管理器,并将此类文件存储到存储库管理器中,并像往常一样使用它们。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM