我做自動化爲我們的項目之一,我編碼方式類似於下面的.exe文件的路徑:如何獲得駐留在SRC /主/資源
public void m() throws FileNotFoundException, IOException {
System.setProperty("webdriver.chrome.driver",Thread.currentThread().getContextClassLoader().getResource("chromedriver.exe").getFile());
System.out.println("123");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
}
它的工作當我執行在日食。但是,當我使用Maven生成JAR測試,它給一個例外:在線程
異常「主要」 java.lang.IllegalStateException:驅動程序可執行文件不存在:C:\Users\rkowsu\Desktop\jar\file:\C:\Users\UU1\Desktop\jar\resources-part-0.0.1-SNAPSHOT.jar!\chromedriver.exe
這有什麼錯?
可能的重複[如何在Maven中使用chrome驅動程序](http://stackoverflow.com/questions/35867102/how-to-work-with-chrome-driver-in-maven) –
我經歷過上面的鏈接示例中,他們提到了chromedriver.exe路徑作爲系統路徑,如果我這樣做,它會起作用。但是,我的要求有點不同。我將.exe文件放在src/main/resources下,我得到了帶有java代碼的.exe路徑,正如我提到的那樣。 – Creator
你可以發佈你的POM.xml嗎? –