1、Git克隆Spring Initializr
网址:https://github.com/spring-io/initializr
git bash中切换0.6.0分支: git checkout 4b9fddd
或者git bash中切换0.7.0分支: git checkout 6a06f54
2、修改根目录pom.xml文件
在initializr工程根目录的pom.xml文件project标签下添加如下内容,用于将本工程上传到NEXUS 的RELEASES仓库
Nexus 2 版本
<distributionManagement>
<repository>
<id>nexus-releases</id>
<url>http://localhost:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
Nexus 3 版本
<distributionManagement>
<repository>
<id>nexus-releases</id>
<url>http://localhost:8081/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<url>http://localhost:8081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
3、Maven配置之servers
.m2/setting.xml文件做如下配置,用户可以上传构件到nexus私服
<servers>
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
4、mvn deploy
上述配置执行完之后,即可在控制台窗口中执行mvn deploy命令,将此工程上传到NEXUS私服完毕。
注意:在initializr工程的根目录执行mvn命令。
5、MAVEN设置之mirrors & profiles & activeProfiles
.m2/setting.xml文件做如下配置,使得maven镜像到NEXUS的中央仓库和RELEASES仓库,注意mirrors里面的子元素顺序决定了路径的匹配顺序。
Nexus 2 版本
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*, !nexus-releases, !nexus-snapshots</mirrorOf>
<url>http://localhost:8081/nexus/content/groups/public/</url>
</mirror>
<mirror>
<!--This sends everything else to /releases, -->
<id>nexus-releases</id>
<mirrorOf>nexus-releases</mirrorOf>
<url>http://localhost:8081/nexus/content/repositories/releases/</url>
</mirror>
<mirror>
<!--This sends everything else to /snapshots, -->
<id>nexus-snapshots</id>
<mirrorOf>nexus-snapshots</mirrorOf>
<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>http://repo1.maven.org/maven2/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<repository>
<id>nexus-releases</id>
<url>http://localhost:8081/nexus/content/repositories/releases/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</repository>
<repository>
<id>nexus-snapshots</id>
<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://repo1.maven.org/maven2/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
<pluginRepository>
<id>nexus-releases</id>
<url>http://localhost:8081/nexus/content/repositories/releases/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</pluginRepository>
<pluginRepository>
<id>nexus-snapshots</id>
<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
Nexus 3 版本
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/repository/maven-public/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>http://repo1.maven.org/maven2/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<repository>
<id>nexus-releases</id>
<url>http://localhost:8081/repository/maven-releases/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</repository>
<repository>
<id>nexus-snapshots</id>
<url>http://localhost:8081/repository/maven-snapshots/</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://repo1.maven.org/maven2/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
<pluginRepository>
<id>nexus-releases</id>
<url>http://localhost:8081/repository/maven-releases/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</pluginRepository>
<pluginRepository>
<id>nexus-snapshots</id>
<url>http://localhost:8081/repository/maven-snapshots/</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
6、安装Spring Boot CLI
0.6.0:网址 http://repo.spring.io/release/org/springframework/boot/spring-boot-cli/2.0.3.RELEASE/
0.7.0:网址 http://repo.spring.io/release/org/springframework/boot/spring-boot-cli/2.1.2.RELEASE/
从以上网址下载zip压缩文件包到本地,解压缩后,参考install.txt文件,将spring-boot-cli/2.0.3.RELEASE\bin的完整路径添加到环境变量PATH中,这样可以在命令行中输入spring命令符,为了校验是否安装成功,输入spring --version查看版本。
7、导入Eclipse工程
将Spring Initializr导入到Eclipse工程中,Java 要求1.8版本以上,并且使用Maven。
8、创建Groovy文件
在项目根目录创建一个新目录(例如,spring-initializr),进入目录,创建initializr.groovy文件,内容如下:
@Grab('io.spring.initializr:initializr-web:0.6.0.RELEASE')
@Grab('spring-boot-starter-web')
class InitializrService { }
9、编译Groovy文件
cd进入spring-initializr,Terminal中执行
spring run initializr.groovy
10、网页生成结果
在浏览器中打开http://localhost:8080,便可使用Spring Initializr了!
本文档介绍了如何将Spring Initializr项目克隆并配置为使用Nexus私服,包括修改pom.xml文件,配置Maven的servers、mirrors、profiles和activeProfiles,安装Spring Boot CLI,以及在Eclipse中导入和运行项目,最终实现通过本地Nexus服务器提供Spring Initializr服务。
1万+

被折叠的 条评论
为什么被折叠?



