![](/img/trans.png)
[英]install a external jar to local repository according to maven's official tutorial,but failed
[英]how we put the external jar's into our local maven repository
在这里,我将构建一个新的Java项目,在这里,该项目需要一些外部jar,这些jar需要由不同的项目重复使用。 How can we store the the external jar's into my local repository and access when when ever we need
“如何在pom.xml中设置特定jar的依赖关系”。
您可以遵循以下步骤: Importing-jars ,但是我认为您应该使用存储库管理器。
首先,您应该设置一个本地存储库管理器(例如Nexus或Artifactory)来代理外部存储库并托管您的本地工件。
然后通过一个简单的命令行执行像这样:
mvn deploy:deploy-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0.1 -Dpackaging=jar -Dfile=c:\oracle_jdbc\jdk16_11.2.0.1\ojdbc6.jar -Durl=http://my-nexus/nexus/content/repositories/thirdparty -DrepositoryId=thirdparty
您将工件上传到存储库管理器(在我的情况下是Nexus)。
从pom中,您可以通过声明一个新的依赖项来获得jar:
<dependency>
<groupId>com.oracle</groupId>
<DartifactId>ojdbc6</DartifactId>
<version>11.2.0.1</version>
</dependency>
初始调用会将Nexus中的jar添加到您的本地.m2(本地存储库)中,以后可用于需要它的任何其他maven项目。
我希望这有帮助。
这是一种对外部JAR(仅一个)进行pom处理的便捷方法
相应的POM.XML文件模板如下。 您必须更改项目的groupId
, artifactId
, version
和属性wrapped-lib-file
,仅此而已。 在示例中,外部lib应该是lib/external.jar
。
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>target-groupId</groupId>
<artifactId>target-artifactId</artifactId>
<version>target-version</version>
<packaging>jar</packaging>
<properties>
<wrapped-lib-file>lib/external.jar</wrapped-lib-file>
</properties>
<build>
<plugins>
<plugin>
<!-- Pomify the external JAR specified by ${wrapped-lib-file} -->
<inherited>false</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>Installation of wrapped library ${wrapped-lib-file}</id>
<phase>install</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>${wrapped-lib-file}</file>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<packaging>jar</packaging>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
然后,您可以在其他项目的依赖项中使用此Pom化的JAR(当然使用目标的groupId,artifactId和版本!)
如果要使用混淆的库作为Maven模块,则此方法将使您免于痛苦。
要在本地存储库中安装JAR,请使用以下命令:
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
如果还有pom文件,则可以使用以下命令进行安装:
mvn install:install-file -Dfile=<path-to-file> -DpomFile=<path-to-pomfile>
使用2.5版的maven-install-plugin会变得更好。 如果JAR是由Apache Maven构建的,则它将在META-INF目录的子文件夹中包含pom.xml,默认情况下将读取该子文件夹。 在这种情况下,您需要做的只是:
mvn install:install-file -Dfile=<path-to-file>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.