gpt4 book ai didi

spring - 在 Spring Boot 中加载 chromedriver

转载 作者:行者123 更新时间:2023-12-04 09:31:02 26 4
gpt4 key购买 nike

我正在运行一个 spring 启动应用程序,我试图让 chromedriver 不是从我的本地目录加载,而是从项目资源文件夹加载。我在 resources/chromedriver.exe 中有我的 chromdriver.exe,但我不确定如何加载它。
我试过这不起作用。尝试将文件路径设为“resources/chromedriver.exe”也不起作用

  String filePath = ClassLoader.getSystemClassLoader().getResource("resources/chromedriver.exe").getFile();
System.out.println(filePath);
System.setProperty("webdriver.chrome.driver", filePath)

最佳答案

如果你使用的是 Spring,你可以试试这个:

import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;



Resource resource = new ClassPathResource("chromedriver.exe");
String filePath = resource.getFile().getPath();

System.out.println(filePath);
System.setProperty("webdriver.chrome.driver", filePath);

关于spring - 在 Spring Boot 中加载 chromedriver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62842334/

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