Reputation: 713
I built a project in IntelliJ using the JavaFX and Selenium libraries. When ran inside the IDE, the project functions as intended. When compiled with mvn clean;mvn compile
, and than executed via it's newly created .jar
file, the JavaFX part of the program works, but the Selenium libraries can not be found. This is my pom.xml
file:
<?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>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<mainClass>Main</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${com.toasttab.Epsonaut}/lib</outputDirectory>
<includeScope>compile</includeScope>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<groupId>com.jagdpanzer.epsonaut</groupId>
<artifactId>Epsonaut</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.43.0</version>
</dependency>
</dependencies>
</project>
How do I successfully build this project so the Selenium dependencies defined in the pom
work outside of the IDE?
EDIT: My MANIFEST.MF file is below.
Manifest-Version: 1.0
Implementation-Title: Epsonaut
Implementation-Version: 1.0-SNAPSHOT
Archiver-Version: Plexus Archiver
Built-By: dougdemars
Implementation-Vendor-Id: com.jadgpanzer.epsonaut
Class-Path: lib/selenium-java-2.43.0.jar lib/selenium-chrome-driver-2.
43.0.jar lib/selenium-remote-driver-2.43.0.jar lib/cglib-nodep-2.1_3.
jar lib/json-20080701.jar lib/selenium-api-2.43.0.jar lib/guava-15.0.
jar lib/selenium-htmlunit-driver-2.43.0.jar lib/htmlunit-2.15.jar lib
/xalan-2.7.1.jar lib/serializer-2.7.1.jar lib/commons-collections-3.2
.1.jar lib/commons-lang3-3.3.2.jar lib/httpmime-4.3.3.jar lib/commons
-codec-1.9.jar lib/htmlunit-core-js-2.15.jar lib/xercesImpl-2.11.0.ja
r lib/xml-apis-1.4.01.jar lib/nekohtml-1.9.21.jar lib/cssparser-0.9.1
4.jar lib/sac-1.3.jar lib/commons-logging-1.1.3.jar lib/jetty-websock
et-8.1.15.v20140411.jar lib/jetty-util-8.1.15.v20140411.jar lib/jetty
-io-8.1.15.v20140411.jar lib/jetty-http-8.1.15.v20140411.jar lib/http
client-4.3.4.jar lib/httpcore-4.3.2.jar lib/selenium-firefox-driver-2
.43.0.jar lib/commons-io-2.4.jar lib/commons-exec-1.1.jar lib/seleniu
m-ie-driver-2.43.0.jar lib/jna-3.4.0.jar lib/platform-3.4.0.jar lib/s
elenium-safari-driver-2.43.0.jar lib/selenium-support-2.43.0.jar lib/
webbit-0.4.15.jar lib/netty-3.5.5.Final.jar
Created-By: Apache Maven 3.3.9
Build-Jdk: 1.8.0_101
Main-Class: Main
Upvotes: 0
Views: 1048
Reputation: 3914
The problem is that your jar's classpath points to the relative directory lib/
while your dependencies are being copied to ${com.toasttab.Epsonaut}/lib
.
Just make sure<outputDirectory>
have the same value as <classpathPrefix>
.
If you want to be able to execute the jar from any path, I would suggest to use maven-assembly-plugin
with the single
goal.
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>your.package.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
and run it with mvn clean compile assembly:single
.
Upvotes: 2
Reputation: 4120
Open final jar file through ZIP, check MANIFEST.MF file Class-Path: values.
All paths there must be accessible from current directory.
Current means from where you call java to execute that jar file.
Upvotes: 1