Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将本地jar文件添加到Maven项目中?_Java_Maven_Dependencies_Libraries_Mvn Repo - Fatal编程技术网

Java 如何将本地jar文件添加到Maven项目中?

Java 如何将本地jar文件添加到Maven项目中?,java,maven,dependencies,libraries,mvn-repo,Java,Maven,Dependencies,Libraries,Mvn Repo,如何将本地jar文件(还不是Maven存储库的一部分)直接添加到项目的库源中?将jar安装到本地Maven存储库中,如下所示: mvn install:install-file \ -Dfile=<path-to-file> \ -DgroupId=<group-id> \ -DartifactId=<artifact-id> \ -Dversion=<version> \ -Dpackaging=<packag

如何将本地jar文件(还不是Maven存储库的一部分)直接添加到项目的库源中?

将jar安装到本地Maven存储库中,如下所示:

mvn install:install-file \
   -Dfile=<path-to-file> \
   -DgroupId=<group-id> \
   -DartifactId=<artifact-id> \
   -Dversion=<version> \
   -Dpackaging=<packaging> \
   -DgeneratePom=true
mvn安装:安装文件\
-D文件=\
-DgroupId=\
-达里法提德=
  • Maven安装插件的用法:

  • 将JAR安装到本地Maven存储库中,如下所示:

    mvn install:install-file \
       -Dfile=<path-to-file> \
       -DgroupId=<group-id> \
       -DartifactId=<artifact-id> \
       -Dversion=<version> \
       -Dpackaging=<packaging> \
       -DgeneratePom=true
    
    mvn安装:安装文件\
    -D文件=\
    -DgroupId=\
    -达里法提德=
    
  • Maven安装插件的用法:

    • 首选方法是创建自己的远程存储库

      有关如何执行此操作的详细信息,请参阅。
      查看“上载到远程存储库”部分。

      首选方法是创建自己的远程存储库

      有关如何执行此操作的详细信息,请参阅。
      请查看“上传到远程存储库”部分。

      当然,您可以将JAR添加到该文件夹。但也许这并不是你想要实现的

      如果需要这些JAR进行编译,请检查以下相关问题:


      另外,在任何人建议之前,不要使用系统作用域。

      当然,您可以将JAR添加到该文件夹中。但也许这并不是你想要实现的

      如果需要这些JAR进行编译,请检查以下相关问题:


      另外,在任何人建议之前,不要使用系统作用域。

      一种方法是将其上载到您自己的Maven存储库管理器(如Nexus)。无论如何,拥有自己的存储库管理器是一种好的做法

      我最近看到的另一个好方法是在构建生命周期中包含Maven安装插件:在POM中声明将文件安装到本地存储库。这是一个小,但小开销和没有手动步骤涉及


      一种方法是将其上传到您自己的Maven存储库管理器(如Nexus)。无论如何,拥有自己的存储库管理器是一种好的做法

      我最近看到的另一个好方法是在构建生命周期中包含Maven安装插件:在POM中声明将文件安装到本地存储库。这是一个小,但小开销和没有手动步骤涉及


      您可以直接添加本地依赖项(如中所述),如下所示:

      mvn install:install-file -Dfile=awesomeapp-1.0.1.jar \ -DpomFile=awesomeapp-1.0.1.pom \ -Dsources=awesomeapp-1.0.1-sources.jar \ -Djavadoc=awesomeapp-1.0.1-javadoc.jar \ -DgroupId=com.example \ -DartifactId=awesomeapp \ -Dversion=1.0.1 \ -Dpackaging=jar
      
      com.sample
      (您可以参与并描述为什么此功能在某些情况下有用)。我希望这个功能仍然存在


      如果你问我,只要这个特性没有被删除,我就用这个在我的项目中只依赖一个不适合存储库的调皮jar文件。如果这个功能被删除,那么,这里有很多好的答案,我以后可以从中选择

      您可以直接添加本地依赖项(如中所述),如下所示:

      mvn install:install-file -Dfile=awesomeapp-1.0.1.jar \ -DpomFile=awesomeapp-1.0.1.pom \ -Dsources=awesomeapp-1.0.1-sources.jar \ -Djavadoc=awesomeapp-1.0.1-javadoc.jar \ -DgroupId=com.example \ -DartifactId=awesomeapp \ -Dversion=1.0.1 \ -Dpackaging=jar
      
      com.sample
      (您可以参与并描述为什么此功能在某些情况下有用)。我希望这个功能仍然存在


      如果你问我,只要这个特性没有被删除,我就用这个在我的项目中只依赖一个不适合存储库的调皮jar文件。如果这个功能被删除,那么,这里有很多好的答案,我以后可以从中选择

      首先,我想把这个答案归功于一个匿名堆栈溢出用户——我很确定我以前在这里看到过类似的答案——但现在我找不到了

      将本地JAR文件作为依赖项的最佳选择是创建本地Maven存储库。这样的存储库只不过是一个包含pom文件的适当目录结构

      以我为例: 我的主项目位于
      ${master_project}
      位置,子项目1位于
      ${master_project}/${subproject1}
      位置

      然后,我在以下位置创建了一个Maven存储库:
      ${master_project}/localmaven repo

      在子项目1中位于
      ${master_project}/${subproject1}/pom.xml
      的pom文件中,需要指定将文件路径作为URL参数的存储库:

      <repositories>
          <repository>
              <id>local-maven-repo</id>
              <url>file:///${project.parent.basedir}/local-maven-repo</url>
          </repository>
      </repositories>
      
      一旦安装了JAR文件,您的Maven repo就可以提交到代码存储库中,并且整个设置是独立于系统的。()


      我同意让JAR致力于源代码repo不是一个好的实践,但在现实生活中,快速而肮脏的解决方案有时比一个完整的nexusrepo更好,它承载一个您无法发布的JAR

      首先,我想把这个答案归功于一个匿名堆栈溢出用户——我很确定我以前在这里看到过类似的答案——但现在我找不到了

      将本地JAR文件作为依赖项的最佳选择是创建本地Maven存储库。这样的存储库只不过是一个包含pom文件的适当目录结构

      以我为例: 我的主项目位于
      ${master_project}
      位置,子项目1位于
      ${master_project}/${subproject1}
      位置

      然后,我在以下位置创建了一个Maven存储库:
      ${master_project}/localmaven repo

      在子项目1中位于
      ${master_project}/${subproject1}/pom.xml
      的pom文件中,需要指定将文件路径作为URL参数的存储库:

      <repositories>
          <repository>
              <id>local-maven-repo</id>
              <url>file:///${project.parent.basedir}/local-maven-repo</url>
          </repository>
      </repositories>
      
      一旦安装了JAR文件,您的Maven repo就可以提交到代码存储库中,并且整个设置是独立于系统的。()

      我同意让JAR致力于源代码repo不是一个好的实践,但在现实生活中,快速而肮脏的解决方案有时比一个完整的nexusrepo更好,它承载一个您无法发布的JAR

      还可以看看

      <scope>compile</scope>
      
      编译
      
      。这是默认设置,但在某些情况下,我发现显式设置该范围也可以在本地存储库中查找本地库。

      还可以查看

      <scope>compile</scope>
      
      编译
      
      。这是默认设置,但我发现在某些情况下,显式地将该范围设置为Maven,以便在本地存储库中查找本地库<
      mvn install:install-file -Dfile=<path-to-file>
      
       mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
      -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
      
      mvn install:install-file -DgroupId= -DartifactId= -Dversion= -Dpackaging=jar -Dfile=path
      
      <properties><local.repository.folder>${pom.basedir}/libs/</local.repository.folder>
      </properties>
      
      <repositories>
         <repository>
              <id>local-maven-repository</id>
              <url>file://${local.repository.folder}</url>
              <releases>
                  <enabled>true</enabled>
              </releases>
              <snapshots>
                  <enabled>true</enabled>
              </snapshots>
         </repository>
      </repositories>
      
      <dependency>
          <groupId>com.mycompany.myproject</groupId>
          <artifactId>myproject</artifactId>
          <version>1.2.3</version>
      </dependency>
      
      mvn install:install-file -Dfile=path-to-jar -DgroupId=owngroupid -DartifactId=ownartifactid -Dversion=ownversion -Dpackaging=jar
      
      mvn install:install-file -Dfile=path-to-jar -DgroupId=com.decompiler -DartifactId=jd-core-java -Dversion=1.2 -Dpackaging=jar
      
      mvn install:install-file -Dfile=c:\kaptcha-{version}.jar -DgroupId=com.google.code
      -DartifactId=kaptcha -Dversion={version} -Dpackaging=jar
      
      <properties>
          <local.sdk>/path/to/jar</local.sdk>
      </properties>
      
      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
          <executions>
              <execution>
                  <id>1</id>
                  <phase>initialize</phase>
                  <goals>
                      <goal>install-file</goal>
                  </goals>
                  <configuration>
                      <groupId>com.local.jar</groupId> 
                      <artifactId>appengine-api</artifactId>
                      <version>1.0</version>
                      <packaging>jar</packaging>
                      <file>${local.sdk}/lib/impl/appengine-api.jar</file>
                  </configuration>
              </execution>
              <execution>
                  <id>appengine-api-stubs</id>
                  <phase>initialize</phase>
                  <goals>
                      <goal>install-file</goal>
                  </goals>
                  <configuration>
                      <groupId>com.local.jar</groupId>
                      <artifactId>appengine-api-stubs</artifactId>
                      <version>1.0</version>
                      <packaging>jar</packaging>
                      <file>${local.sdk}/lib/impl/appengine-api-stubs.jar</file>
                  </configuration>
              </execution>
          </executions>
      </plugin>
      
      <dependency>
          <groupId>com.local.jar</groupId>
          <artifactId>appengine-api</artifactId>
          <version>1.0</version>
      </dependency>
      
      <dependency>
          <groupId>com.local.jar</groupId>
          <artifactId>appengine-api-stubs</artifactId>
          <version>1.0</version>
          <scope>test</scope>
      </dependency>
      
      mvn install:install-file
         -Dfile=<path-to-file>
         -DgroupId=<group-id>
         -DartifactId=<artifact-id>
         -Dversion=<version>
         -Dpackaging=<packaging>
         -DgeneratePom=true
      
       <dependency>
            <groupId>com.google.code</groupId>
            <artifactId>kaptcha</artifactId>
            <version>2.3</version>
       </dependency>
      
      <url>file:${basedir}</url>
      
      <dependency>
          <groupId>org.example</groupId>
          <artifactId>example</artifactId>
          <version>1.0</version>
          <scope>system</scope>
          <systemPath>${pom.basedir}/src/lib/example.jar</systemPath>
      </dependency>
      
      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-install-plugin</artifactId>
          <executions>
              <execution>
                  <id>install-external-non-maven-jar-MWS-Client-into-local-maven-repo</id>
                  <phase>clean</phase>
                  <configuration>
                      <repositoryLayout>default</repositoryLayout>
                      <groupId>com.amazonservices.mws</groupId>
                      <artifactId>mws-client</artifactId>
                      <version>1.0</version>
                      <file>${project.basedir}/lib/MWSClientJavaRuntime-1.0.jar</file>
                      <packaging>jar</packaging>
                      <generatePom>true</generatePom>
                  </configuration>
                  <goals>
                      <goal>install-file</goal>
                  </goals>
              </execution>
          </executions>
      </plugin>
      
          <dependency>
              <groupId>com.amazonservices.mws</groupId>
              <artifactId>mws-client</artifactId>
              <version>1.0</version>
          </dependency>
      
      plugins {
          id 'org.springframework.boot' version '2.2.2.RELEASE'
          id 'io.spring.dependency-management' version '1.0.8.RELEASE'
          id 'java'
      }
      
      group = 'com.example'
      version = '0.0.1-SNAPSHOT'
      sourceCompatibility = '1.8'
      
      repositories {
          mavenCentral()
          flatDir {
             dirs 'libs' // local libs folder
         }
      }
      
      dependencies {
          implementation 'org.springframework.boot:spring-boot-starter-web'
          testImplementation('org.springframework.boot:spring-boot-starter-test') {
              exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
          }
          
          implementation 'io.grpc:grpc-netty-shaded:1.29.0'
          implementation 'io.grpc:grpc-protobuf:1.29.0'
          implementation 'io.grpc:grpc-stub:1.29.0' // dependecies from maven central
      
          implementation name: 'akka-actor_2.12-2.6.1' // dependecies from lib folder
          implementation name: 'akka-protobuf-v3_2.12-2.6.1'
          implementation name: 'akka-stream_2.12-2.6.1'
      
       }
      
      mvn install:install-file -Dfile=awesomeapp-1.0.1.jar \ -DpomFile=awesomeapp-1.0.1.pom \ -Dsources=awesomeapp-1.0.1-sources.jar \ -Djavadoc=awesomeapp-1.0.1-javadoc.jar \ -DgroupId=com.example \ -DartifactId=awesomeapp \ -Dversion=1.0.1 \ -Dpackaging=jar