maven项⽬加载本地JAR
将jar安装到本地的maven仓库
1.⾸先确定本地有maven环境。
2.安装本地jar
模板:
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
⽰例:
mvn install:install-file -Dfile=F:\jave-ffmpegjave-1.0.2.jar -DgroupId=ffmpegjave -DartifactId=java-ffmpegjave -Dversion=1.0.2 -Dpackaging=jar
<path-to-file>: 要安装的JAR的本地路径
<group-id>:要安装的JAR的Group Id
<artifact-id>: 要安装的JAR的 Artificial Id
<version>: JAR 版本
<packaging>: 打包类型,例如JAR
注意:最好在l⽂件所在的⽬录运⾏上述命令,个⼈经验不在根⽬录运⾏有时会安装不成功
如图出现SUCCESS就表⽰安装成功。
3.引⽤jar
到安装的pom,打开复制引⽤
如:
<dependency>
<groupId>ffmpegjave</groupId>
<artifactId>java-ffmpegjave</artifactId>
<version>1.0.2</version>
</dependency>
这种⽅法弊端较⼤,程序的可维护性以及移植性较低。例如当你改变本地Maven仓库时需要重新安装。如果引⽤此JAR的项⽬是多⼈协调⼯作的项⽬,则每个⼈都要将其安装在⾃⼰的本地仓库。
解决办法
可以将此JAR⽂件放在⼯程的根⽬录下,让其随着项⽬⾛,然后在l⽂件中使⽤maven-install-plugin在Maven初始化阶段完成安装。
如图
<project xmlns="/POM/4.0.0" xmlns:xsi="/2001/XMLSchema-instance" xsi:schemaLocation="/POM/4.0.0 /xsd/maven-4.0.0. <modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.watch.parent</groupId>
<artifactId>children-watch-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<!-- 公共项⽬ -->
<groupId>com.watchmons</groupId>
<artifactId>children-watch-commons</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>children-watch-commons</name>
<url></url>
<dependencies>
<!-- amr录⾳转换为mp3 -->
<dependency>
<groupId>ffmpegjave</groupId>
<artifactId>java-ffmpegjave</artifactId>
<version>1.0.2</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<groupId>ffmpegjave</groupId>
<artifactId>java-ffmpegjave</artifactId>
<version>1.0.2</version>
<packaging>jar</packaging>
<file>${basedir}/lib/java-ffmpegjave-1.0.2.jar</file>
</configuration>
</execution>
</executions>
</plugin>
<!--如果使⽤Eclipse报错的话,加⼊如下代码-->
<!--This plugin's configuration is used to store Eclipse m2e settings only.
It has no influence on the Maven build itself. -->
<plugin>
<groupId&lipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId&jo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<versionRange>[1.0,)</versionRange>
maven打包本地jar包<goals>
<goal>test-compile</goal>
<goal>compile</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-install-plugin
</artifactId>
<versionRange>
[2.5,)
</versionRange>
<goals>
<goal>install-file</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>false</runOnIncremental>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
SpringBoot的配置
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<groupId>ffmpegjave</groupId>
<artifactId>java-ffmpegjave</artifactId>
<version>1.0.2</version>
<packaging>jar</packaging>
<file>${basedir}/lib/java-ffmpegjave-1.0.2.jar</file>
</configuration>
</execution>
</executions>
</plugin>
${basedir}表⽰l⽂件所在的⽬录
然后打包测试看是否能引⽤到。如图
我这⾥是聚合⼯程,jar是在公共项⽬中引⽤的,我netty项⽬要⽤到只需要引⽤公共项⽬就可以了,jar也会⼀起引⽤过来的。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论