Making HTTP post request (with an input type=“file”) from within Maven, using command line parameters if possible

后端 未结 2 1471
天命终不由人
天命终不由人 2021-01-27 06:38

I would like to convert this bash script:

#!/bin/bash
if ! [ $# == 2 ]; then
   echo Usage: update-module admin-password module-file
   exit 1
fi
if ! [ -f $2 ];         


        
2条回答
  •  感情败类
    2021-01-27 07:42

    Use GMaven to embed an inline Groovy Script, and use apache httpclient to implement the post request. Something like this:

    
        org.codehaus.groovy.maven
        gmaven-plugin
        
            
                org.apache.httpcomponents
                httpclient
                4.0.2
            
        
        
            
                generate-resources
                
                    execute
                
                
                    
                
            
        
    
    

    This uses the maven properties http.url and http.attachmentFile that you can specify on the command line using the -D syntax or in a pom.xml file in a block. Obviously, you'd need to extend the functionality to what else your shell script is doing, but this should get you started.

提交回复
热议问题