从grails服务调用phantom.js

时间:2013-07-23 09:53:39

标签: grails phantomjs

我需要从grails服务调用phantom.js脚本来创建我可以缓存的PNG图像。

我在幻像和grails中看到的所有示例都涉及使用幻像进行测试,所以我不确定如何通过服务来管理它。

从grails服务调用脚本时,最佳实践是什么?

它使用自定义脚本根据传入的URL创建图像。

这将是命令行上的equivelant:

./ phantomjs createImage.js http://www.toBeConcerted.com output.png

2 个答案:

答案 0 :(得分:5)

这与从Java或Groovy调用可执行文件相同。

对于此主题,Groovy文档有a specific page。您还可以查看this related SO question

Groovy示例

def command = """phantomjs createImage.js http://www.toBeConcerted.com output.png"""// Create the String
def proc = command.execute()                 // Call *execute* on the string
proc.waitFor()                               // Wait for the command to finish

答案 1 :(得分:0)

我建议您查看PhantomJS的WebDriver实现,其名称为Ghost Driver 它包含在PhantomJS 1.9+中,可以从Grails轻松调用