这里我将构建一个新的java项目,这里项目需要一些外部jar,需要不同的项目重复使用。How can we store the the external jar's into my local repository and access when when ever we need
'我们如何在pom.xml中设置特定jar的依赖关系。
答案 0 :(得分:0)
您可以遵循: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项目使用。
我希望这会有所帮助。
答案 1 :(得分:0)
这是 pomify 外部JAR(只有一个)的便捷方法
相应的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>
然后,您可以在其他项目的依赖项中使用此Pomified JAR(使用目标&#39; s groupId,artifactId和版本当然!)
如果您打算使用混淆的库作为Maven模块,这种方法可以让您免于痛苦。
答案 2 :(得分:0)
要在本地存储库中安装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>