㈠ maven怎麼安裝本地jar包
在Maven項目中使用本地JAR包有兩種方法:
1. 使用system scope
<dependencies>
<dependency>
<groupId>org.richard</groupId>
<artifactId>my-jar</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/my-jar.jar</systemPath>
</dependency>
</dependencies>
system scope引入的包,在使用jar-with-dependencies打包時將不會被包含,可以使用resources將本地包打進jar-with-dependencies
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>xxx-jar-with-dependencies</finalName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<targetPath>lib/</targetPath>
<directory>lib/</directory>
<includes>
<include>**/my-jar.jar</include>
</includes>
</resource>
</resources>
</build>
生成的xxx-jar-with-dependencies.jar中,將會包含lib目錄以及my-jar.jar,並且能夠被在執行的時候被找到。
有的時候這種方法會實效,比如JDBCDriver在聲明的時候Class.forName("xxx.Driver")就會說找不到類,用下面兩種方法就可以。
2. 將jar包安裝到本地repository中
mvn install:install-file -Dfile=my-jar.jar -DgroupId=org.richard -DartifactId=my-jar -Dversion=1.0 -Dpackaging=jar
3. 添加 in project repository,在新機器上執行時就不用運行mvn install:install-file命令了
<repository>
<id>in-project</id>
<name>In Project Repo</name>
<url>file://${project.basedir}/lib</url></repository>
<dependency>
<groupId>org.richard</groupId>
<artifactId>my-jar</artifactId>
<version>1.0</version>
</dependency>
你的jar包及路徑必須嚴格遵循格式:
/groupId/artifactId/version/artifactId-verion.jar
本例中: lib/org/richard/my-jar/1.0/my-jar-1.0.jar
㈡ 如何在maven中添加本地jar包
<dependency>
<groupId>javabuilder</groupId>
<artifactId>javabuilder</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/javabuilder.jar
</systemPath>
</dependency>
像這樣把包拷到項目裡面,然後指定到項目下面就可以了。
㈢ 如何在maven中添加本地jar包
1、首先我在項目根目錄中創建一個lib文件夾,將jar包拷貝到lib文件夾下
2、然後我們在maven的pom.xml中配置
<groupId>org.wltea.analyzer</groupId>
<artifactId>IKAnalyzer</artifactId>
<version>2012FF_u1</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/IKAnalyzer2012FF_u1.jar
</systemPath>
3、這里的groupId和artifactId以及version都是可以隨便填寫的 ,scope必須填寫為system,而systemPath我們現在我們jar包的地址就可以了
4、最後我們必須在maven打包的過程中加入我們這個jar包。因為項目運行的時候需要這個Jar,並且我們得拷貝在WEB-INF/lib目錄下
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<directory>${project.basedir}/lib</directory>
<targetPath>WEB-INF/lib</targetPath>
<filtering>false</filtering>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
</webResources>
</configuration>
<version>2.1.1</version>
㈣ 如何在maven中添加本地jar包
1、首先我在項目根目錄中創建一個lib文件夾,將jar包拷貝到lib文件夾下
2、然後我們在maven的pom.xml中配置
[html] view plain
<groupId>org.wltea.analyzer</groupId>
<artifactId>IKAnalyzer</artifactId>
<version>2012FF_u1</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/IKAnalyzer2012FF_u1.jar
</systemPath>
㈤ 如何用maven 手動把本地jar安裝到本地倉庫
1、從Maven官網下載Maven安裝包,本文使用的Maven版本是Maven3.2.3,解壓後文件目錄如下:
至此,手動添加完成,此時在pom.xml文件中添加相應的依賴就可以使用該JAR包了。
四、Maven常用命令解釋
mvn clean:清空輸出目錄(即 target 目錄)
mvn compile:編譯源代碼
mvn package:生成構件包(一般為 jar 包或 war 包)
mvn install:將構件包安裝到本地倉庫
mvn deploy:將構件包部署到遠程倉庫
執行 Maven 命令需要注意的是:必須在 Maven 項目的根目錄處執行,也就是當前目錄下一定存在一個名為 pom.xml 的文件。
㈥ 如何在maven的pom.xml中添加本地jar包
步驟:
1.cmd命令進入該jar包所在路徑
2.執行命令:
mvn install:install-file -Dfile=lucene-queryparser-4.6.1.jar
-DgroupId=org.apache.lucene -DartifactId=lucene-queryparser
-Dversion=4.6.1 -Dpackaging=jar
其中:-DgroupId和-DartifactId的作用是指定了這個jar包在repository的安裝路徑,只是用來告訴項目去這個路徑下尋找這個名稱的jar包。
比如:
mvn install:install-file -Dfile=hadoop-hdfs-2.2.0.jar
-DgroupId=org.apache.hadoop -DartifactId=hadoop-hdfs -Dversion=2.2.0 -D
-Dpackaging=jar
就是指把hadoop-hdfs-2.2.0.jar安裝到repository\org.apache.hadoop\hadoop-hdfs\2.2.0目錄下,執行完命令後,如果需要在項目中使用這個jar,則在pom.xml中添加如下配置即可:
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-hdfs</artifactId>
<version>2.2.0</version>
</dependency>
注意在每個參數前有個-D
二、怎麼在pom.xml中添加項目中libs下的jar呢,而不是從本地倉庫中添加?
1、首先將要添加的jar包復制到項目中的libs文件夾下
2、然後在pom.xml中添加如下代碼:
[html] view plain
<dependency>
<groupId>htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.21-OSGi</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/htmlunit-2.21-OSGi.jar</systemPath>
</dependency>
注意scope元素和systemPath元素,其中systemPath元素指定的就是jar包在項目中的路徑。
注意libs文件夾下的這個jar包不需要Add to Build Path
㈦ 如何在maven的pom.xml中添加本地jar包
但也有特殊情況。
比如我下載了
lucene-queryparser-4.6.1.jar
一、怎麼添加jar到本地倉庫呢?
步驟:
1.cmd命令進入該jar包所在路徑
2.執行命令:
mvn install:install-file -Dfile=lucene-queryparser-4.6.1.jar -DgroupId=org.apache.lucene -DartifactId=lucene-queryparser -Dversion=4.6.1 -Dpackaging=jar
其中:-DgroupId和-DartifactId的作用是指定了這個jar包在repository的安裝路徑,只是用來告訴項目去這個路徑下尋找這個名稱的jar包。
比如:
mvn install:install-file -Dfile=hadoop-hdfs-2.2.0.jar -DgroupId=org.apache.hadoop -DartifactId=hadoop-hdfs -Dversion=2.2.0 -D -Dpackaging=jar
㈧ 如何在maven中添加本地jar包
將jar包安裝到本地repository中 mvn install:install-file -Dfile=my-jar.jar -DgroupId=org.richard -DartifactId=my-jar -Dversion=1.0 -Dpackaging=jar2.添加 in project repository
㈨ 如何在maven中添加本地jar包
原則上Maven的設計是不需要這么做的,因為pom.xml中依賴的jar包會自動實現從中央倉庫下載到本地倉庫。但是公司設計了一個setting,如果本地倉庫沒有,就去setting指定的url中下載jar包,如果還沒有就報錯。
考慮到setting中url的jar包比較老,如果需要用最新的,則需要將jar包手動下載到本地倉庫。
比如我下載了
lucene-queryparser-4.6.1.jar
怎麼添加到本地倉庫呢?
步驟:
1.cmd命令進入該jar包所在路徑
2.執行命令
mvn install:install-file -Dfile=lucene-queryparser-4.6.1.jar -DgroupId=org.apache.lucene -DartifactId=lucene-queryparser -Dversion=4.6.1 -Dpackaging=jar
(不同的jar包相對應替換對應部分)
另外我嘗試了下面的方法,發現不行:
直接寫一個空的pom,里頭包含對所需要jar包的依賴,通過這種方式希望將jar包下載到本地倉庫。但是應用代碼中沒用到,maven命令沒有下載這個jar包到本地倉庫。
補充,-DgroupId和-DartifactId的作用其實是指定了這個jar包的安裝在repository的安裝路徑,只是用來告訴項目去這個路徑下尋找這個名稱的jar包。比如:
mvn install:install-file -Dfile=freemarker-2.3.13.jar -DgroupId=freemarker -DartifactId=freemarker -Dversion=2.3.13 -Dpackaging=jar
就是安裝到了repository\freemarker\freemarker\2.3.13目錄下,如果在dependency的依賴里也這么寫的話,就可以到對應的目錄去尋找。
對於maven中存在classifier的,例如
org.apache.hadoop
hadoop-hdfs
2.2.0
tests
就加一個-D參數就可以了,如下:
mvn install:install-file -Dfile=hadoop-hdfs-2.2.0-tests.jar -DgroupId=org.apache.hadoop -DartifactId=hadoop-hdfs -Dversion=2.2.0 -Dclassifier=tests -Dpackaging=jar