Nexus私服环境下Spring Initializr配置本地服务

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 版本


   
      nexus-releases
      http://localhost:8081/nexus/content/repositories/releases/
   
   
      nexus-snapshots
      http://localhost:8081/nexus/content/repositories/snapshots/
   

Nexus 3 版本


    
        nexus-releases
        http://localhost:8081/repository/maven-releases/
    
    
        nexus-snapshots
        http://localhost:8081/repository/maven-snapshots/
    

3、Maven配置之servers

.m2/setting.xml文件做如下配置,用户可以上传构件到nexus私服


    
        nexus-releases
        admin
        admin123
    
    
        nexus-snapshots
        admin
        admin123
    

4、mvn deploy

上述配置执行完之后,即可在控制台窗口中执行mvn deploy命令,将此工程上传到NEXUS私服完毕。

注意:在initializr工程的根目录执行mvn命令。

5、MAVEN设置之mirrors & profiles & activeProfiles

.m2/setting.xml文件做如下配置,使得maven镜像到NEXUS的中央仓库和RELEASES仓库,注意mirrors里面的子元素顺序决定了路径的匹配顺序。

Nexus 2 版本

  
    
      
      nexus
      *, !nexus-releases, !nexus-snapshots
      http://localhost:8081/nexus/content/groups/public/
    
    
      
      nexus-releases
      nexus-releases
      http://localhost:8081/nexus/content/repositories/releases/
    
    
      
      nexus-snapshots
      nexus-snapshots
      http://localhost:8081/nexus/content/repositories/snapshots/
    
  
  
    
      nexus
      
      
      
        
          central
          http://repo1.maven.org/maven2/
          true
          true
        
        
          nexus-releases
          http://localhost:8081/nexus/content/repositories/releases/
          true
          false
        
        
          nexus-snapshots
          http://localhost:8081/nexus/content/repositories/snapshots/
          false
          true
        
      
     
        
          central
          http://repo1.maven.org/maven2/
          true
          true
        
        
          nexus-releases
          http://localhost:8081/nexus/content/repositories/releases/
          true
          false
        
        
          nexus-snapshots
          http://localhost:8081/nexus/content/repositories/snapshots/
          false
          true
        
     
    
  
  
  
    
    nexus
    

Nexus 3 版本


    
      
      nexus
      *
      http://localhost:8081/repository/maven-public/
    


    
      nexus
      
      
      
        
          central
          http://repo1.maven.org/maven2/
          true
          true
        
        
          nexus-releases
          http://localhost:8081/repository/maven-releases/
          true
          false
        
        
          nexus-snapshots
          http://localhost:8081/repository/maven-snapshots/
          false
          true
        
      
     
        
          central
          http://repo1.maven.org/maven2/
          true
          true
        
        
          nexus-releases
          http://localhost:8081/repository/maven-releases/
          true
          false
        
        
          nexus-snapshots
          http://localhost:8081/repository/maven-snapshots/
          false
          true
        
     
    

  

    
    nexus
  

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了!

你可能感兴趣的:(开发环境搭建)