2016-11-13 72 views
1

我正在创建maven应用程序,我从网站获取信息。未找到maven包类selenium Web驱动程序

我创建Maven的包,但是当我使用命令运行的jar: “Java的罐子APP-1.0-SNAPSHOT.jar” 我得到这个错误:

“抛出java.lang.ClassNotFoundException:org.openqa。 selenium.WebDriver“

它运行良好,当我在IntelliJ中运行它。

这是我的POM:

<groupId>app</groupId> 
<artifactId>app</artifactId> 
<version>1.0-SNAPSHOT</version> 

<dependencies> 
<dependency> 
    <groupId>org.seleniumhq.selenium</groupId> 
    <artifactId>selenium-java</artifactId> 
    <version>2.53.1</version> 
</dependency> 
<dependency> 
    <groupId>org.seleniumhq.selenium</groupId> 
    <artifactId>selenium-htmlunit-driver</artifactId> 
    <version>2.52.0</version> 
</dependency> 
    <dependency> 
     <groupId>com.itextpdf</groupId> 
     <artifactId>itextpdf</artifactId> 
     <version>5.0.6</version> 
    </dependency> 
</dependencies> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <configuration> 
       <source>1.8</source> 
       <target>1.8</target> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-jar-plugin</artifactId> 
      <configuration> 
       <archive> 
        <manifest> 
         <addClasspath>true</addClasspath> 
         <classpathPrefix>lib/</classpathPrefix> 
         <mainClass>sample.Main</mainClass> 
        </manifest> 
       </archive> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-dependency-plugin</artifactId> 
      <version>2.10</version> 
      <executions> 
       <execution> 
        <id>copy-dependencies</id> 
        <phase>package</phase> 
        <goals> 
         <goal>copy-dependencies</goal> 
        </goals> 
        <configuration> 
         <includeScope>runtime</includeScope> 
         <outputDirectory>${project.build.directory}/dependency-jars/</outputDirectory> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

请帮我找出什么是错的。谢谢!

回答

0

有可能是版本不匹配的几率如下:

Starting with 2.53.0 you need to explicitly include HtmlUnitDriver as a dependency to include it. Version number of the driver is now tracking HtmlUnit itself.

<dependency> 
    <groupId>org.seleniumhq.selenium</groupId> 
    <artifactId>htmlunit-driver</artifactId> 
    <version>2.53.1</version> 
</dependency> 

保持硒的Java和HTMLUnitDriver的版本相同。

OR

有可能是对硒的服务器standalone.jar依赖

If you are using DefaultSelenium (or the RemoteWebDriver implementation), you still need to start a Selenium server. The best way is to download the selenium-server-standalone.jar from the Selenium Downloads page and just use it. Furthermore you can also embed the Selenium server into your own project, if you add the following dependency to your pom.xml:

<dependency> 
    <groupId>org.seleniumhq.selenium</groupId> 
    <artifactId>selenium-server</artifactId> 
    <version>3.0.1</version> 
</dependency> 

Note: Be aware, that the selenium-server artifact has a dependency to the servlet-api-2.5 artifact, which you should exclude, if your project will be run inside a web application container.

参考:

http://www.seleniumhq.org/download/maven.jsp

+0

感谢您的回复。不幸的是它没有帮助。 Htmlunit驱动程序最新版本是2.52.0。我将selenium-java的版本更改为2.52.0,但没有成功。 – Liam

+0

您是否尝试添加硒服务器(用于版本2.52.0)的依赖关系? –

+0

是的,仍然是相同的情况:( – Liam