Maven 发布jar包到远程仓库


1、Maven 插件安装

使用eclipse安装Maven插件

操作步骤:

eclipse: 【help】-> 【Install New Software】->【Add】

输入Maven插件的下载地址


2、settings.xml 文件配置

Maven本地仓库路径配置

Maven缺省的本地仓库地址为${user.home}/.m2/repository 。也就是说,一个用户会对应的拥有一个本地仓库。当然你可以通过修改${user.home}/.m2/settings.xml 配置这个地址;

<settings>   
    <localRepository> D:/jav/repository</localRepository>   
</settings>  

远程仓库登录用户名/密码配置

<servers>
    <server>
      <id>cdsfdev</id>
      <username>admin</username>
      <password>123456</password>
    </server>
    <server>
      <id>cdsfdev-snapshots</id>
      <username>admin</username>
      <password>123456</password>
    </server>
</servers>
 

3、pom.xml 文件配置

<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/maven-v4_0_0.xsd">

	<modelVersion>4.0.0</modelVersion>
	<groupId>com.cdsf.gov</groupId>
	<artifactId>GsmModuleService</artifactId>
	<packaging>war</packaging>
	<version>0.0.1-SNAPSHOT</version>
	<url>http://maven.apache.org</url>

	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>3.8.1</version>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<build>
		<resources>
			<resource>
				<directory>src/main/conf</directory>
			</resource>
			<resource>
				<directory>src/main/java</directory>
				<includes>
					<include>**/*.xml</include>
				</includes>
			</resource>
		</resources>
		<testOutputDirectory>target/test-classes</testOutputDirectory>
		<testSourceDirectory>src/test/java</testSourceDirectory>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-war-plugin</artifactId>
				<version>2.6</version>
				<configuration>
					<archive>
						<manifestEntries>
							<System-Name>${artifactId}</System-Name>
							<System-Code>---replace me-----</System-Code>
						</manifestEntries>
					</archive>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.tomcat.maven</groupId>
				<artifactId>tomcat7-maven-plugin</artifactId>
				<version>2.2</version>
				<configuration>
					<port>8080</port>
					<path>/${artifactId}</path>
					<uriEncoding>UTF-8</uriEncoding>
				</configuration>
			</plugin>
		</plugins>
	</build>

	<profiles>

		<!--OA webService -->
		<profile>
			<id>gsm-api</id>
			<activation>
				<activeByDefault>false</activeByDefault>
			</activation>
			<build>
				<plugins>
					<plugin>
						<groupId>org.apache.maven.plugins</groupId>
						<artifactId>maven-jar-plugin</artifactId>
						<version>2.5</version>
						<configuration>
							<finalName>${project.artifactId}-api-${project.version}</finalName>
							<!-- 配置对外API包含的类 -->
							<includes>
								<include>com/sefon/api/*</include>
								<include>com/sefon/GsmModule/*</include>
							</includes>
						</configuration>
						<executions>
							<execution>
								<goals>
									<goal>jar</goal>
								</goals>
								<phase>package</phase>
							</execution>
						</executions>
					</plugin>
					<plugin>
						<groupId>org.apache.maven.plugins</groupId>
						<artifactId>maven-assembly-plugin</artifactId>
						<version>2.5.1</version>
						<configuration>
							<finalName>${project.artifactId}-api-${project.version}-sources</finalName>
							<appendAssemblyId>false</appendAssemblyId>
							<attach>false</attach>
							<descriptors>
								<descriptor>${basedir}/api-assembly.xml</descriptor>
							</descriptors>
						</configuration>
						<executions>
							<execution>
								<goals>
									<goal>single</goal>
								</goals>
								<phase>package</phase>
							</execution>
						</executions>
					</plugin>
					<plugin>
						<groupId>org.apache.maven.plugins</groupId>
						<artifactId>maven-deploy-plugin</artifactId>
						<version>2.8.2</version>
						<configuration>
							<file>target/${project.artifactId}-api-${project.version}.jar</file>
							<groupId>com.cdsf.egov</groupId>
							<artifactId>${project.artifactId}-api</artifactId>
							<version>${project.version}</version>
							<sources>target/${project.artifactId}-api-${project.version}-sources.jar</sources>
							<packaging>jar</packaging>
							<generatePom>true</generatePom>
							<repositoryId>${deploy.repo}</repositoryId>
						</configuration>
						<executions>
							<execution>
								<phase>deploy</phase>
								<goals>
									<goal>deploy-file</goal>
								</goals>
								<configuration>
									<url>${deploy.url}</url>
								</configuration>
							</execution>
						</executions>
					</plugin>
				</plugins>
			</build>
		</profile>

		<profile>
			<id>api-snapshot</id>
			<activation>
				<activeByDefault>false</activeByDefault>
			</activation>
			<properties>
				<deploy.url>http://10.0.4.124:8081/nexus/content/repositories/cdsfdev-snapshots/</deploy.url>
				<deploy.repo>cdsfdev-snapshots</deploy.repo>
			</properties>
		</profile>
		<profile>
			<id>api-release</id>
			<activation>
				<activeByDefault>false</activeByDefault>
			</activation>
			<properties>
				<deploy.url>http://10.0.4.124:8081/nexus/content/repositories/cdsfdev/</deploy.url>
				<deploy.repo>cdsfdev</deploy.repo>
			</properties>
		</profile>
	</profiles>


	<repositories>
		<repository>
			<id>maven-central-mirror</id>
			<url>http://10.0.4.124:8081/nexus/content/repositories/cdsfdev/</url>
		</repository>
		<repository>
			<id>maven-3rd-party</id>
			<url>http://10.0.4.124:8081/nexus/content/repositories/thirdparty/</url>
		</repository>
		<repository>
			<id>maven-central-mirror-snapshot</id>
			<url>http://10.0.4.124:8081/nexus/content/repositories/cdsfdev-snapshots/</url>
			<snapshots>
				<enabled>true</enabled>
			</snapshots>
		</repository>
	</repositories>

	<distributionManagement>
		<repository>
			<id>cdsfdev</id>
			<url>http://10.0.4.124:8081/nexus/content/repositories/cdsfdev/</url>
		</repository>
		<snapshotRepository>
			<id>cdsfdev-snapshots</id>
			<url>http://10.0.4.124:8081/nexus/content/repositories/cdsfdev-snapshots/</url>
		</snapshotRepository>
	</distributionManagement>
</project>

4、Maven 发布包命令

-P gsm-api,api-snapshot deploy -Dmaven.test.skip=true



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值