说明
maven是个非常好用的东西,但是前提是有外网才能随心所欲。如果是内网项目呢,那就需要我们自己搭建一个私有仓库了,具体怎么搭建百度上有一大堆的资料,这里就不讲解了。这里我们主要说一下当我们需要上传私有jar包的时候,该如何上传?
上传jar到私有仓库
使用搭建的私有仓库的页面地址上传
这种上传也是可以的,但是过程稍麻烦一点
使用maven命令上传
使用maven命令,首先配置好maven的settings配置文件以及mavevn项目的pom.xml
- 找到settings里面的localRepository节点位置,添加localRepository节点配置,这里配置的是从maven下载的jar存放的地方也就是本地仓库
- 找到settings里面的servers节点位置,添加私服的账号和密码,这里的id为releases和snapshots,这个id你可以随便取只要和下面的配置一致即可,我这里代表的两个是私服的两个仓库
- 找到settings里面的mirrors节点位置,配置仓库地址,这里的id和上面的一致
- 找到settings里面的profiles节点位置,这里配置的要多一点,不用截图了
<profiles>
<!--profile 节点可以配置多个 只要id不一样就可以 在下面的activeProfiles节点就可以选择活跃的profile节点-->
<profile>
<id>dev</id>
<repositories>
<repository>
<id>releases</id>
<!--请输入你自己的地址-->
<url>http://IP/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>snapshots</id>
<!--请输入你自己的地址-->
<url>http://IP/repository/maven-snapshots/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>releases</id>
<!--请输入你自己的地址-->
<url>http://IP/repository/maven-snapshots/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>snapshots</id>
<!--请输入你自己的地址-->
<url>http://IP/repository/maven-snapshots/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<!--
| Here is another profile, activated by the system property 'target-env' with a value of 'dev',
| which provides a specific path to the Tomcat instance. To use this, your plugin configuration
| might hypothetically look like:
|
| ...
| <plugin>
| <groupId>org.myco.myplugins</groupId>
| <artifactId>myplugin</artifactId>
|
| <configuration>
| <tomcatLocation>${tomcatPath}</tomcatLocation>
| </configuration>
| </plugin>
| ...
|
| NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
| anything, you could just leave off the <value/> inside the activation-property.
|
<profile>
<id>env-dev</id>
<activation>
<property>
<name>target-env</name>
<value>dev</value>
</property>
</activation>
<properties>
<tomcatPath>/path/to/tomcat/instance</tomcatPath>
</properties>
</profile>
-->
</profiles>
- 找到settings里面的activeProfiles节点位置,这里配置的是活跃的profile的地方。
- 修改pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>com.xing</groupId>
<artifactId>demo</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<distributionManagement>
<!-- 这里写的就是你想上传的仓库,一般都是写一个第三方仓库 -->
<!--<repository>
<id>releases</id>
<name>Nexus Release Repository</name>
<url>http://10.33.66.159:8081/repository/maven-public/</url>
</repository>-->
<snapshotRepository>
<id>snapshots</id>
<name>Nexus Snapshots Repository</name>
<!-- 请填写你自己的仓库地址 -->
<url>http://IP/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
</project>
- 使用命令
maven clean deploy -U
整个项目截图:
如有错误之处,请指正,不胜感激。如有疑惑,留言即可。