springboot+vue 项目持续部署

安装nodejs

  • 下载

    wget  https://nodejs.org/dist/latest-v8.x/node-v8.11.3-linux-x64.tar.gz
  • 解压

    tar -zxvf node-v8.11.3-linux-x64.tar.gz
  • 创建软链接

    cd node-v8.11.3-linux-x64/bin        
    sudo ln -s node /usr/local/bin/node    
    sudo ln -s npm /usr/local/bin/npm
  • 查看版本

    node -v
    npm -v

jenkins设定

  • 新建job:省略
  • 设定pom编译前执行的命令:

    • 进入到工程目录,npm安装和webpack

      cd jenkins下该项目的workspace
         npm install
         node_modules/.bin/webpack

出现错误1:

[INFO] --- maven-clean-plugin:2.6.1:clean (default-clean) @ testProject ---
[INFO] 
[INFO] --- exec-maven-plugin:1.5.0:exec (npm install (initialize)) @ testProject ---
[ERROR] Command execution failed.
java.io.IOException: Cannot run program "npm" (in directory "/home/jenkins/workspace/testProject"): error=2, No such file or directory
  • 解决:
    在命令行查看npm -v就知道真相了。这是nodejs安装前,或是安装后没把命令放到/usr/local/bin时出的错误。

出现错误2:从jenkins控制台看信息,执行到npm install就没有下文了,一直跳舞中。。。

  • 解决:进入命令行执行pom编译前执行的命令,即

    # cd jenkins下该项目的workspace
         # npm install  //出现了错误4
         # node_modules/.bin/webpack
    执行后,node_modules文件夹就出现在工程目录了。
  • 注:

    • 不知道根本原因,讲道理的话,在jenkins配置执行命令也该好使。
    • 第一次在命令行执行后,下次jenkins编译就不会出这个问题了。

出现错误3:发布成功后,访问url,500错误,错误信息截取如下:

javax.servlet.ServletException: java.lang.LinkageError: loader constraint violation: when resolving method "org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(Ljavax/servlet/ServletConfig;)Lorg/apache/tomcat/InstanceManager;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/WEB_002dINF/jsp/login_jsp, and the class loader (instance of java/net/URLClassLoader) for the method's defining class, org/apache/jasper/runtime/InstanceManagerFactory, have different Class objects for the type org/apache/tomcat/InstanceManager used in the signature
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:358) ~[jasper.jar:8.0.9]
  • 原因:外部tomcat的jar包与springboot内置tomcat的jar包冲突导致
  • 解决: pom.xml修改

    <dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-tomcat</artifactId>
           <scope>provided</scope>
       </dependency>

    重新jenkins发布后,访问正常。
    修改pom后,项目下WEB-INF/lib下的jar包没有了这仨包:tomcat-embed-core-8.5.11.jar, tomcat-embed-el-8.5.11.jar,tomcat-embed-websocket-8.5.11.jar

    springboot+vue 项目持续部署

出现错误4:在命令行进入到项目的workspace执行npm install出现如下错误

Miscellaneous Warning ETIMEDOUT: request to https://registry.npmjs.org/karma-phantomjs-launcher fail
  • 解决:

执行 $ npm config list

; cli configs
metrics-registry = "https://registry.npmjs.org/"
scope = ""
user-agent = "npm/5.6.0 node/v8.11.3 linux x64"

; node bin location = /usr/local/src/node-v8.11.3-linux-x64/bin/node
; cwd = /tmp/phantomjs
; HOME = /home/tomcat
; "npm config ls -l" to show all defaults.

执行 $ npm config set registry http://registry.npmjs.org/
执行 $ npm config list

; cli configs
metrics-registry = "http://registry.npmjs.org/"
scope = ""
user-agent = "npm/5.6.0 node/v8.11.3 linux x64"

; userconfig /home/tomcat/.npmrc
registry = "http://registry.npmjs.org/"

; node bin location = /usr/local/src/node-v8.11.3-linux-x64/bin/node
; cwd = /tmp/phantomjs
; HOME = /home/tomcat
; "npm config ls -l" to show all defaults.

相关推荐