Java의 NoClassDefFoundError : com / google / common / base / Function
다음 코드를 실행할 때 :
public static void main(String[] args) {
try {
FirefoxDriver driver = new FirefoxDriver();
driver.get("http:www.yahoo.com");
} catch (NoClassDefFoundError ex) {
System.out.println("error: " + ex.getStackTrace());
}
}
다음과 같은 오류가 발생했습니다.
오류 : [Ljava.lang.StackTraceElement; @ 80f4cb
스레드 "main"java.lang.NoClassDefFoundError의 예외 : com / google / common / base / Function
누군가가 해결책이나 이유를 찾도록 도와 줄 수 있습니까?
나는 같은 문제가 있었고 마침내 selenium-server-standalone-version.jar 추가하는 것을 잊었다는 것을 발견했습니다 . 클라이언트 jar 인 selenium-java-version.jar 만 추가했습니다 .
도움이 되었기를 바랍니다.
A NoClassDefFoundError
는 JRE가 클래스를 찾을 수 없을 때 발생합니다. 귀하의 경우에는 클래스 com.google.common.base.Function
경로에 추가하지 않은 클래스를 찾을 수 없습니다 .
편집하다
다음 라이브러리를 다운로드 한 후 :
- 셀레늄 : http://code.google.com/p/selenium/downloads/list
- 구아바 : http://code.google.com/p/guava-libraries/downloads/list
- Apache HttpComponents : http://hc.apache.org/downloads.cgi
- JSON jar : http://www.jarfinder.com/index.php/jars/versionInfo/21653
압축을 풀고 모든 JAR 파일을라는 폴더 lib
, 테스트 클래스 에 넣습니다 .
import org.openqa.selenium.firefox.FirefoxDriver;
public class Test {
public static void main(String[] args) {
try{
FirefoxDriver driver = new FirefoxDriver();
driver.get("http:www.yahoo.com");
} catch(Exception e){
e.printStackTrace();
}
}
}
아무 문제없이 달렸습니다.
다음과 같이 클래스를 컴파일하고 실행할 수 있습니다.
# Linux 및 Mac에서 컴파일 및 실행 javac -cp. : lib / * Test.java java -cp. : lib / * 테스트 # Windows에서 컴파일 및 실행 javac -cp.; lib / * Test.java java -cp.; lib / * 테스트
같은 오류가 발생하고 조사 후 라이브러리 selenium-api 2.41.0에는 guava 15.0이 필요하지만 이전 버전으로 재정의되었으므로 pom.xml에 다음 구성을 추가하여 guava 15.0을 직접 종속성으로 선언했습니다.
<dependency>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
<type>jar</type>
<version>15.0</version>
</dependency>
클래스 경로 에 "google-collections" 라이브러리 가 없습니다 .
클래스 경로에 라이브러리를 추가 하는 방법 에는 여러 가지가 있으므로 프로그램을 실행하는 방법에 대한 자세한 정보를 제공하십시오.
명령 줄에서 다음을 통해 클래스 경로에 라이브러리를 추가 할 수 있습니다.
java -classpath path/lib.jar ...
나를 위해 jar-selenium-java-2.45.0.jar을 선택하는 것 외에도 셀레늄 루트 폴더 아래의 "libs"폴더에있는 모든 jar를 선택해야했습니다.
Please include all the jar files of selenium stand-alone and lib folder, then this error will resolved
It looks like you're trying to import some google code:
import com.google.common.base.Function;
And it's not finding it the class Function. Check to make sure all the required libraries are in your build path, and that you typed the package correctly.
I met the same problem and fail even after installing the 'selenium-server-standalone-version.jar', I think you need to install the guava and guava-gwt jar (https://code.google.com/p/guava-libraries/) as well. I added all of these jar, and finally it worked in my PC. Hope it works for others meeting this issue.
I had the same issue. I found that I forgot to add selenium-2.53.0/selenium-java-2.53.0-srcs.jar file to my project's Reference library.
I got the same error, but it was resolved if you add the libraries of selenium (again if you haven't), if you are using INTELIJ
project>projectStructure>Module>+>add the selenium jars (both from lib folder and outside ones.).
Same needs to be done for other IDE's as well, like eclipse.
When I caught the exception java.lang.NoClassDefFoundError: com/google/common/base/Function
it was caused by errors in Project Libraries.
Please check it in your project settings. For Intellij IDEA go to File - Project Structure and select Modules tab. All I needed to do to resolve this exception was re-adding the selenium library
After you extract your "selenium-java-.zip" file you need to configure your build path from your IDE. Import all the jar files under "lib" folder and both selenium standalone server & Selenium java version jar files.
I wanted to try a simple class outside IDE and stuff. So downloaded selenium zip from website and run the class like this:
java -cp selenium-2.50.1/*:selenium-2.50.1/libs/*:. my/package/MyClass <params>
I had the issue that I initially used lib
instead of libs
. I didn't need to add selenium standalone jar. This is Java 8 that understands wildcards in classpath. I think java 7 would also do.
I had the same problem, and finally I found that I forgot to add the selenium-server-standalone-version.jar. I had only added the client jar, selenium-java-version.jar.
this is for chrome
System.setProperty("webdriver.chrome.driver","D:\\Testing_offical\\chromedriver.exe");
driver =new ChromeDriver();
this is for fire fox
System.setProperty("webdriver.gecko.driver",""D:\\Testing_offical\\geckodriver.exe"");
driver =new FirefoxDriver();
pattern :
System.setProperty("webdriver.gecko.driver","**Path of the gecko driver** ");
Note download gecko from here :- http://docs.seleniumhq.org/download/
ReferenceURL : https://stackoverflow.com/questions/5134953/noclassdeffounderror-in-java-com-google-common-base-function
'programing tip' 카테고리의 다른 글
Maven에서 생성 된 jar에서 리소스를 제외하는 방법은 무엇입니까? (0) | 2020.12.27 |
---|---|
byte []로 드로어 블 (0) | 2020.12.27 |
목록에서 가장 가까운 번호를 얻는 방법 (0) | 2020.12.27 |
배경 이미지 위치 지정, 패딩 추가 (0) | 2020.12.27 |
Twitter Bootstrap 3에서 기본적으로 이미지가 반응하지 않습니까? (0) | 2020.12.27 |