在項目pom文件目錄打開命令,輸入以下命令,替換各個屬性名,這些屬性值如果不清楚可以在jar包解壓后的pom.properties內可查看
mvn install:install-file -Dfile=xxx.jar -DgroupId=com.microsoft.sqlserver -DartifactId=xxxId -Dversion=x.x -Dpackaging=jar
一般這樣就成功了,但是如果出現以下問題:
就需要修改命令為
mvn org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install-file -Dfile=xxx.jar
提示成功
另:maven打jar包依賴
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.6.1</version> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> <optimize>true</optimize> <showDeprecation>true</showDeprecation> <showWarnings>true</showWarnings> <compilerArgument>-Xlint:all,-serial,-path,-rawtypes,-unchecked</compilerArgument> <skip>true</skip> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>3.1.1</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>3.0.0</version> <configuration> <!--如果想在沒有web.xml文件的情況下構建WAR,請設置為false。--> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> </plugins> <resources> <resource> <directory>src/main/resources</directory> <includes> <!-- 此處設置打成jar包后保留的靜態資源文件 .txt .xml等--> <include>**/*.md</include> </includes> </resource> </resources> </build>
idea在右邊maven工具欄中使用package即可
如需上傳至私服,需要配置倉庫地址:
<distributionManagement> <snapshotRepository> <id>maven-001</id> <!-- name和url需要到私服配置中查看 --> <name>xxx</name> <url>http://xxx</url> </snapshotRepository> </distributionManagement>
然后在本地maven的settings.xml中加入配置:
<server> <!-- id需與pom文件中的id對應 --> <id>maven-001</id> <username>xxx</username> <password>xxx</password> </server>
idea的maven配置內的settings需指向此文件,如果使用的是默認的配置,也就是\.m2\repository,需要在m2文件夾新建settings.xml文件,然后將配置項填入
配置好后,點擊idea的meven工具欄內的deploy即可上傳