gpt4 book ai didi

java - 当 PhantomJS 嵌入到 jar 文件中时如何使用 phantomjs.binary.path?

转载 作者:行者123 更新时间:2023-11-30 08:20:48 24 4
gpt4 key购买 nike

我正在使用 phantomjs 进行 headless 浏览器测试。我从我的 java 文件 (MainTest.java) 中调用 phantomjs。代码在我的本地机器上运行良好。我将 phantomjs.exe 和调用 java 文件捆绑在一个 jar 文件 (tetsPhantom.jar) 中。

  • testPhantom.jar
    • phantomjs.exe
    • 主测试.java

在服务器上,它试图找到 phantomjs 可执行路径时失败:

String webDir = LiExportEmails.class.getProtectionDomain().getCodeSource().getLocation().toExternalForm(); // Returns http://myservername.com:8080/testPhatom.jar
System.setProperty("phantomjs.binary.path", webDir);

我也尝试将其设置为 http://myservername.com:8080/testPhatom.jar!phantomjs.exe,但仍然失败。

与调用方位于同一 jar 文件中的 phantomjs 的正确路径应该是什么?

最佳答案

使用 JNLP Webstart Launch Issue 中的方法解决了它和 Copying a binary file outside of a jar ,有一个变化:

File f = new File ("./phantomjs.exe");
if (!f.exists()) {
InputStream in = Myclass.class.getClassLoader().getResourceAsStream("phantomjs.exe");
OutputStream out = new FileOutputStream("./phantomjs.exe");
IOUtils.copy(in, out);
}
System.setProperty("phantomjs.binary.path","./phantomjs.exe");

关于java - 当 PhantomJS 嵌入到 jar 文件中时如何使用 phantomjs.binary.path?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25708033/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com