1. 编译项目并发布到本地仓库
mvn clean install
2. 项目发布到私服
mvn clean deploy
3. 将项目依赖项拷贝到目录target/lib
mvn dependency:copy-dependencies -DoutputDirectory=target/lib
4. 将jar包放在本地仓库
mvn install:install-file -DgroupId=customjar.importdirectly -DartifactId=ojdbc -Dversion=15.0 -Dpackaging=jar -Dfile=E:\ojdbc-15.0.jar
pom.xml中引用如下:
<dependency>
<groupId>customjar.importdirectly</groupId>
<artifactId>ojdbc</artifactId>
<version>15.0</version>
</dependency>
5.将项目发布到私服
<distributionManagement>
<repository>
<id>jzy3d-ftp</id>
<name>Jzy3d Maven Folder</name>
<url>ftp://ftp.cluster013.ovh.net/maven/releases</url>
</repository>
<snapshotRepository>
<id>jzy3d-ftp</id>
<name>Jzy3d Maven Folder SNAPSHOTS</name>
<url>ftp://ftp.cluster013.ovh.net/maven/snapshots</url>
</snapshotRepository>
</distributionManagement>
首先指定私服release和snapshot的Reposity中的id、name、url,这些可以直接在$M2_HOME\conf\settings.xml中找到,如果你使用的私服的话。
其次$M2_HOME\conf\settings.xml文件中Servers下需要配置相关登陆信息
<server>
<id>xxx-release</id>
<username>deployment</username>
<password>deployment123</password>
</server>
具体细节隐去。
6. 将jar包发布到私服(非本地仓库)
mvn deploy:deploy-file -DgroupId=customjar.importdirectly –DartifactId=commons-math3
-Dversion=3.2.lastUpdated -Dfile=D:\log\customjar\importdirectly\commons-math3\3.2\commons-math3-3.2.jar.lastUpdated
-DrepositoryId=xx-release -Durl=http://ip:port/nexus/content/repositories/xx-release
凡是涉及到上传到私服的均需配置可上传的账号,不过默认一般为:
<server>
<id>xxx-snapshot</id>
<username>deployment</username>
<password>deployment123</password>
</server>
7. maven插件
7.1 将所有的依赖项都包含,生成一个独立的jar包
<build>
<plugins>
<!-- any other plugins -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
7.2 springboot 插件
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
8. maven项目构建
比较灵活,简单点就构建多模块modules项目,分解成子项目,只需要在根目录下mvn clean install,maven reactor自动帮你处理编译先后顺序。
随意点就添加depxendency手动一个一个编译,编译顺序自己控制好就行了。