Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
157 views
in Technique[技术] by (71.8m points)

java - How can I resolve my class from a different jar with same structure like another

How can I resolve my class from a different jar with same structure like another

Note : Though the jars in question contains the word selenium but the question here have no direct relation with selenium

Till a few days back PhantomJSDriver was released bundled along with selenium-server-standalone-v.v.v.jar. So my Class was working fine as:

import java.io.File;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;

public class A_PhantomJS
{
    public static void main(String[] args) 
    {
          File path=new File("C:\Utility\phantomjs-2.1.1-windows\bin\phantomjs.exe");
          System.setProperty("phantomjs.binary.path",path.getAbsolutePath());
          WebDriver driver= new PhantomJSDriver();
          driver.manage().window().maximize();
          driver.get("https://www.google.co.in");
    }
}

Now selenium-server-standalone-v.v.v.jar doesn't bundles the jar for PhantomJSDriver dependency.

So I have downloaded the jar phantomjsdriver-1.1.0.jar and added as an external jar to my project.

You can see the structure of the phantomjsdriver-1.1.0.jar is similar to what it was earlier when it was bundled with selenium-server-standalone-v.v.v.jar

PhantomJSDriver

Now, though my Class gets resolved through:

import org.openqa.selenium.phantomjs.PhantomJSDriver;

But I am facing a Runtime exception of java.lang.NoClassDefFoundError as follows:

Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/browserlaunchers/Proxies
    at org.openqa.selenium.phantomjs.PhantomJSDriverService.createDefaultService(PhantomJSDriverService.java:178)
    at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:99)
    at org.openqa.selenium.phantomjs.PhantomJSDriver.<init>(PhantomJSDriver.java:89)
    at demo.A_PhantomJS.main(A_PhantomJS.java:15)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.browserlaunchers.Proxies
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 4 more

Line 15 being:

WebDriver driver= new PhantomJSDriver();

As per the error I have searched for org.openqa.selenium.browserlaunchers.Proxies within the phantomjsdriver-1.1.0.jar unable to find any clue.

NoClassDefFoundError

Can anyone help me out please?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This jar includes org.openqa.selenium.browserlaunchers.Proxies, try adding it to your classpath:

https://search.maven.org/remotecontent?filepath=org/seleniumhq/selenium/selenium-api/2.4.0/selenium-api-2.4.0.jar

If you miss other classes, you can search them by classname with Advanced Search on Maven Central Repository: https://search.maven.org/#advancedsearch%7Cgav


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...