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


当前回答

<dependency>
    <groupId>group id name</groupId>
    <artifactId>artifact name</artifactId>
    <version>version number</version>
    <scope>system</scope>
    <systemPath>jar location</systemPath>
</dependency>

其他回答

指向${project.directory}/rebo/或file://uri的pom存储库可以与源驻留jarfiles一起工作,用于一个小项目的dep。这些信息不会泄漏到系统~/.m2 repo中,但如果未指定,则会影响maven版本选择与(通常是最近的)顶级版本的选择。

对于现有的dep,如果您可以使用“target”作为您最喜欢的结构或maven的默认值运行,则在分发时绑定的dep与shade类似,但更直接:

-cp“$PWD/target/classs:$PWD/target/lib/*”pkg.random.ClassWithMain

then

<build>
        <plugins>
            <plugin>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>install</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>

下载jar文件将jar文件复制到项目文件夹get inteliJ idea Maven命令区键入以下命令

mvn安装:安装文件-Dfile=YOUR_JAR_file_LOCATION*JARNAME.JAR-DgroupId=org.primefaces.themes-DastifactId=iMetro-Dversion=1.0.1-Dpackage=JAR*


例子:

mvn安装:安装文件-Dfile=C:\Users\ranushka.l\Desktop\test\spring-web-1.0.2.jar-DgroupId=org.primefaces.themes-DartifactId=iMetro-Dversion=1.0.1-Dpackage=jar

您可以直接添加本地依赖项(如build maven项目中所述,包含专有库),如下所示:

<dependency>
    <groupId>com.sample</groupId>
    <artifactId>sample</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/src/main/resources/Name_Your_JAR.jar</systemPath>
</dependency>

使现代化

在新版本中,此功能被标记为已弃用,但仍在工作,尚未删除(您只需在maven启动期间的日志中看到警告)。maven集团对此提出了一个问题https://issues.apache.org/jira/browse/MNG-6523(您可以参与并描述此功能在某些情况下有帮助的原因)。我希望这一功能仍然存在!

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

在POM文件中添加您自己的本地JAR,并在maven构建中使用它。

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

然后将其添加到POM中,如下所示:

根项目上进行构建

您可以在命令行中编写以下代码,或者如果您使用eclipse内置maven,右键单击项目->运行方式->运行配置…->在左侧面板中,右键单击Maven Build->new configuration->在基本目录中的Goals&中编写代码:${project_loc:NameOfYourProject}->运行

mvn install:install-file
   -Dfile=<path-to-file>
   -DgroupId=<group-id>
   -DartifactId=<artifact-id>
   -Dversion=<version>
   -Dpackaging=<packaging>
   -DgeneratePom=true

其中每一个都指:

<path to file>:要加载的文件的路径,例如->c:\kapcha-2.3jar

<group id>:文件应在例如com.google.code下注册的组

<artifact-id>:文件的工件名称,例如->kappcha

<version>:文件的版本,例如->2.3

<package>:文件的打包,例如->jar

2.安装后,只需在pom.xml中声明jar。

 <dependency>
      <groupId>com.google.code</groupId>
      <artifactId>kaptcha</artifactId>
      <version>2.3</version>
 </dependency>