我使用 IntelliJ Idea 创建了一个可以完美编译的代码,因此我决定为其分发创建相应的 JAR
。
为了创建 JAR
文件,我将清单文件保存到名为 resources
的文件夹中,然后执行 IntelliJ 提供的命令,在名为 JAR
的文件夹中创建了一个文件target
在我的项目中。
(我按照 this 步骤创建可执行文件)
问题是,当我尝试编译我之前创建的 JAR
文件时,通过终端执行 java -jar executable.jar
或通过在 IDE
中右键单击运行,我得到了这个输出错误:
线程“main”中的异常java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver
我该如何解决这个问题?似乎可执行文件跳过了 pom.xml
文件中声明的一些依赖项...
pom.xml:
<?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>pumpbot</groupId>
<artifactId>maven-pumpbot</artifactId>
<version>1.0-SNAPSHOT</version>
<licenses>
<license>
<name>The MIT License</name>
<url>https://opensource.org/licenses/MIT</url>
</license>
</licenses>
<properties>
<com.squareup.retrofit2.version>2.4.0</com.squareup.retrofit2.version>
</properties>
<dependencies>
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>retrofit</artifactId>
<version>${com.squareup.retrofit2.version}</version>
</dependency>
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>converter-jackson</artifactId>
<version>${com.squareup.retrofit2.version}</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.6</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>