简体   繁体   English

Maven-需要时在哪里存储外部jar文件

[英]maven - where to store external jar files if needed

What is the convention to store jar files inside maven project? 在Maven项目中存储jar文件的约定是什么? I know that I should download jars using maven itself, but this time the case is different. 我知道我应该使用maven本身下载jar,但是这次情况有所不同。 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. 我正在上一门课程(coursera.org),我有一些应该使用的秘密jar文件,而且它不是公开的-我不会用maven下载它。 And I do want to store the .jar file in my private repo (bitbucket). 而且我确实希望将.jar文件存储在我的私有存储区(bitbucket)中。 The question is just where should I put the file, so that maven project will be able to use this jar. 问题是我应该将文件放在哪里,以便Maven项目将能够使用此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 这是执行此操作的另一种简单方法:在项目目录中创建基于文件的Maven存储库

Pros: - Anyone can checkout the project and do a maven compile - No need to install a repository manager 优点: -任何人都可以签出项目并进行Maven编译-无需安装存储库管理器

Cons: - The jar will be in project directory 缺点: -jar将在项目目录中

How to do this? 这个怎么做? I am including ojdbc6.jar in a project. 我在项目中包含ojdbc6.jar。

Step 1: Copy the ojdbc6.jar to ${project.baseDir}/lib/com/oracle/driver/ojdbc6/SNAPSHOT/ojdbc6-SNAPSHOT.jar 步骤1:将ojdbc6.jar复制到$ {project.baseDir} /lib/com/oracle/driver/ojdbc6/SNAPSHOT/ojdbc6-SNAPSHOT.jar

Step 2: Add the dependency in your pom 步骤2:在pom中添加依赖项

<dependency>
    <groupId>com.oracle.driver</groupId>
    <artifactId>ojdbc6</artifactId>
    <version>SNAPSHOT</version>
</dependency>

Step 3: Add this to your pom. 步骤3:将其添加到pom。 Here we are asking maven to consider the lib directory inside your project dir as a maven repo. 在这里,我们要求Maven将项目目录中的lib目录视为Maven存储库。

<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 步骤4:在步骤2中分析jar文件的路径。$ {project.baseDir} /lib/com/oracle/driver/ojdbc6/SNAPSHOT/ojdbc6-SNAPSHOT.jar

  • com/oracle/driver/ -- groupId (must be 3 components) com / oracle / driver /-groupId(必须为3个组件)
  • ojdbc6/ -- artifactId ojdbc6 / --artifactId
  • SNAPSHOT/ -- verison 快照/-版本

We have stored the jar, very similar to how maven stores in a repo. 我们已经存储了jar,这与maven在回购中的存储方式非常相似。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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