我想转换这个 bash 脚本:
#!/bin/bash
if ! [ $# == 2 ]; then
echo Usage: update-module admin-password module-file
exit 1
fi
if ! [ -f $2 ]; then
echo Error: module file $2 does not exist
exit 1
fi
curl -c /tmp/cookie.txt -d uname=admin -d pw=${1} http://localhost:8080/openmrs/loginServlet
curl -b /tmp/cookie.txt -F action=upload -F update=true -F moduleFile=\@$2 http://localhost:8080/openmrs/admin/modules/module.list
rm -rf /tmp/cookie.txt > /dev/null 2>&1
可以放入 Maven pom.xml 文件中的内容。
请注意,模块文件是一个 jar 文件(重命名为 .omod),管理密码最好在命令行上指定,类似于 maven archetype:create 的命令行参数http://maven.apache.org/guides/mini/guide-creating-archetypes.html#Alternative_way_to_start_creating_your_Archetype http://maven.apache.org/guides/mini/guide-creating-archetypes.html#Alternative_way_to_start_creating_your_Archetype
(理想情况下,主机名也应该在命令行上指定)。
谢谢
你的
米沙
Use GMaven http://docs.codehaus.org/display/GMAVEN/ to 嵌入内联 Groovy 脚本 http://docs.codehaus.org/display/GMAVEN/Executing+Groovy+Code#ExecutingGroovyCode-ExecuteanInlineGroovyScript,并使用apache httpclient http://hc.apache.org/来实现post请求。像这样的东西:
<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.0.2</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source><![CDATA[
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.impl.client.DefaultHttpClient;
String url = pom.properties['http.url'];
File file = new File(pom.properties['http.attachmentFile'])
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url);
InputStreamEntity entity = new InputStreamEntity(file.newInputStream());
post.setEntity entity;
HttpResponse response = client.execute(post);
]]></source>
</configuration>
</execution>
</executions>
</plugin>
这使用了 Maven 属性http.url
and http.attachmentFile
您可以使用 -D 语法在命令行上或在 pom.xml 文件中指定<properties>
堵塞。显然,您需要将功能扩展到 shell 脚本正在执行的其他操作,但这应该可以帮助您入门。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)