我正在尝试运行basic Selenium example.指定了pom.xml,以包含可执行文件的入口点.jar:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>MySel20Proj</groupId>
<artifactId>MySel20Proj</artifactId>
<version>1.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>main.java.SeleniumTest</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.48.2</version>
</dependency>
</dependencies>
</project>
我可以运行Maven安装;但是,当我从Selenium教程执行包含示例代码的jar时,我收到NoClassDefFoundError:/ org / openqa / selenium / webdriver,表明selenium-java jar的Maven安装失败了。
有没有办法解决这个问题而不将selenium jar添加到本地类路径?似乎没有从Maven Central建立的解决方案被认为是有害的。
答案 0 :(得分:1)
我认为问题在于您没有将依赖的jar(在本例中为Selenium)添加到包含示例代码的jar中。您可以添加以下插件以将Selenium添加到示例代码jar。
<build>
<plugins>
<!-- any other plugins -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
How can I create an executable JAR with dependencies using Maven?