WAR generated by Maven with unresolved compilation problems - java

I am trying to generate a WAR using Maven via command line with the following command:
mvn clean package
Which correctly builds a WAR file, but when I open the file with 7-Zip I can see that there are some classes with compilation problems where the body of the methods just contain something like this:
throw new Error("Unresolved compilation problem: \n");
Although the compiled classes in target/classes are correct. They do not have compilation problems.
Looking at the Maven debug log I can it for the problematic classes:
[DEBUG] - WEB-INF/classes/test/Test.class wasn't copied because it has already been packaged for overlay [currentBuild].
Here is the build part of my pom.xml:
<build>
<sourceDirectory>JavaSource</sourceDirectory>
<resources>
<resource>
<directory>JavaSource</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>true</failOnMissingWebXml>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addClasspath>true</addClasspath>
</manifest>
<manifestEntries>
<Implementation-Build>${project.version}</Implementation-Build>
</manifestEntries>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
</configuration>
</plugin>
</plugins>
</build>
Can you guys help me on that?
EDIT 1:
The dependencies are correctly set in my pom.xml. That's even a good point. It seems that the unresolved compilation problems come from unresolved classes that are in a different jar in my project.
Here is my full pom.xml:
<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>test</groupId>
<artifactId>test-war</artifactId>
<version>1</version>
<packaging>war</packaging>
<parent>
<groupId>test</groupId>
<artifactId>test-pom</artifactId>
<version>1.0.0</version>
</parent>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.0.6</version>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.6</version>
</dependency>
</dependency>
<dependency>
<groupId>javaee</groupId>
<artifactId>javaee-api</artifactId>
<version>5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>test</groupId>
<artifactId>test-client</artifactId>
<version>1</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>JavaSource</sourceDirectory>
<resources>
<resource>
<directory>JavaSource</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>true</failOnMissingWebXml>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addClasspath>true</addClasspath>
</manifest>
<manifestEntries>
<Implementation-Build>${project.version}</Implementation-Build>
</manifestEntries>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>

Related

Maven : no main manifest attribute, in target/xx.jar, Unable to execute jar file

Here is the 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>dl4j</groupId>
<artifactId>dl4j</artifactId>
<version>1.0-SNAPSHOT</version>
<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>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>example.JavaTestExample</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-core</artifactId>
<version>1.0.0-beta3</version>
</dependency>
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-native-platform</artifactId>
<version>1.0.0-beta3</version>
</dependency>
<dependency>
<groupId>org.datavec</groupId>
<artifactId>datavec-api</artifactId>
<version>1.0.0-beta3</version>
</dependency>
<!-- You need the below dependency to use CodecRecordReader-->
<dependency>
<groupId>org.datavec</groupId>
<artifactId>datavec-data-codec</artifactId>
<version>1.0.0-beta3</version>
</dependency>
<!-- <dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>${moduleName}-platform</artifactId>
<version>${moduleVersion}-1.4.4</version>
</dependency>-->
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv-platform</artifactId>
<version>1.4.4</version>
</dependency>
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacpp</artifactId>
<version>1.4.4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.8.0-beta4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.8.0-beta4</version>
</dependency>
<!-- You need the below dependency to use LocalTransformExecutor-->
<dependency>
<groupId>org.datavec</groupId>
<artifactId>datavec-local</artifactId>
<version>1.0.0-beta3</version>
</dependency>
</dependencies>
<!-- Uncomment to use snapshot version -->
<!--<repositories>
<repository>
<id>snapshots-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy> <!– Optional, update daily –>
</snapshots>
</repository>
</repositories>-->
</project>
I wanted to run maven-assembly-plugin and create a jar file with all dependencies added to it. When I run java -jar jarfile.jar, I get the below error:
no main manifest attribute, in target/jarfile.jar
I went through several Stack Overflow posts for the same and tried all permutations and combinations. I tried adding both assembly and shade plugins. You can see the settings I have in my pom.xml above. I'm not really sure on how this is happening even though I added proper maven settings.
I verified that Java is running fine:
I verified whether I specified the main class correctly.
Everything looks fine for me except the results and I'm confused at the moment.
What might be going wrong? I expect some of them still mark the question as "duplicate", but I have been reading other posts and tried changing the settings accordingly. None of them worked.
Good quality question!
I think this will help achieve your goal.
This is what I use to build a clickable JavaFX Jar with all dependencies included.
This is using maven-jar-plugin and maven-shade-plugin rather than maven-assembly-plugin; Here is a good resource on the differences.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>10</release>
</configuration>
</plugin>
<plugin>
<!-- I think you don't need this one -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>${mainClass}</mainClass>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>
${mainClass}
</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer" />
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>${mainClass}</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

How can I create an executable JAR without including 3PP dependencies using Maven?

I want to package my project in a single executable JAR. The problem is I want to execlude any 3PP and just deliver my project due to licensing issues. I have dependencies to another project for building this standalone instance. but Maven will give me Error message when I am running
"mvn clean install assembly:assembly"
The Pom.Xml look like this:
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<groupId>se.ect.apc</groupId>
<artifactId>ect-app-validator</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>AppValidator</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<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.5</version>
<configuration>
<archive>
<manifestEntries>
<Build-Time>${maven.build.timestamp}</Build-Time>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>se.ect.main.EctMain</mainClass>
</manifest>
<manifestEntries>
<Build-Time>${maven.build.timestamp}</Build-Time>
</manifestEntries>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<argLine>-XX:-UseSplitVerifier</argLine>
</configuration>
</plugin>
<!-- -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.7</version>
<configuration>
<dependencyLocationsEnabled>false</dependencyLocationsEnabled>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>se.ect</groupId>
<artifactId>ect-core</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.1.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.3</version>
</plugin>
<!-- exists in apache parent -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<show>private</show>
<nohelp>true</nohelp>
<excludes>**/AppTest.java,**/ParserTestBase.java,**/Test*.java</excludes>
<excludePackageNames>se.ect.mom.testtools</excludePackageNames>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>emma-maven-plugin</artifactId>
<version>1.0-alpha-3</version>
<inherited>true</inherited>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.2</version>
<configuration>
<linkXRef>false</linkXRef>
<sourceEncoding>utf-8</sourceEncoding>
<minimumTokens>100</minimumTokens>
<targetJdk>1.8</targetJdk>
<!-- <excludes> <exclude>**/Test*.java</exclude> </excludes> -->
<excludeRoots>
<excludeRoot>target</excludeRoot>
</excludeRoots>
</configuration>
</plugin>
</plugins>
</reporting>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.6</version>
<scope>compile</scope>
</dependency>
</dependencies>
</dependencyManagement>

How to Include specific jars in WAR, WEB-INF/lib directory with maven

This is my pom.xml, trying to create a WAR file with specific 3 libraries in WEB-INF/lib directory.
I include them in <packagingIncludes> tag and the they are packaged in lib dir, but all .class files are ignored.
I cannot use <packagingExcludes> because the dependent project has many 3rd party jars and out of my control.
what is wrong here or is there a way i can ignore all jars except 3 specific jars?
<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>1.0</modelVersion>
<parent>
<groupId>frmId</groupId>
<artifactId>frm</artifactId>
<version>1.5.9</version>
</parent>
<artifactId>frmw</artifactId>
<packaging>war</packaging>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<packagingIncludes>WEB-INF/lib/frm-fl*.jar,WEB-INF/lib/frm-bean*.jar,WEB-INF/lib/frm-facade-${ffm.fpi.version}.jar</packagingIncludes>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>com.fortify.ps.maven.plugin</groupId>
<artifactId>sca-maven-plugin</artifactId>
<version>${maven-sca-plugin.version}</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.fi.ps</groupId>
<artifactId>frmc-fl</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
You just have to put your 3 specific libraries as dependencies of the project and maven will put it on WEB-INF/lib during package phase
Update:
To exclude JAR comming from dependencies you have to use this kind of syntax
<dependency>
<groupId>sample.ProjectA</groupId>
<artifactId>Project-A</artifactId>
<version>1.0</version>
<exclusions>
<exclusion> <!-- declare the exclusion here -->
<groupId>sample.ProjectB</groupId>
<artifactId>Project-B</artifactId>
</exclusion>
</exclusions>
</dependency>
And to exclude all sub dependencies (maven 3 only):
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
Update 2
with maven-war-plugin you should add WEB-INF/classes/** to packagingIncludes
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<packagingIncludes>WEB-INF/lib/frm-fl*.jar,WEB-INF/lib/frm-bean*.jar,WEB-INF/lib/frm-facade-${ffm.fpi.version}.jar,WEB-INF/classes/**></packagingIncludes>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>

Unnecessary dependencies when bundling javafx application with maven

I am building a JavaFX application with maven, using the javafx maven plugin. Now when I execute mvn jfx:jar, it copies a lot of unnecessary jars into the resulting lib dir, like:
ant-1.8.2.jar
maven-antrun-plugin-1.7.jar
maven-plugin-api-2.0.11.jar
and many more. So, it's basically everything I use for compiling the application - but it's certainly not needed for running it. I feel like I should add a <scope>compile</scope> somewhere in the POM, but the <plugin> element doesn't take one as child. How can I tell maven not to include the plugins I use for compilation in the lib directory created with mvn jfx:jar?
Edit: here's the POM if it helps:
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.flyx.dsa.heldendokument</groupId>
<artifactId>parent</artifactId>
<version>0.1-SNAPSHOT</version>
</parent>
<artifactId>gui</artifactId>
<version>0.1-SNAPSHOT</version>
<name>gui</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.15</version>
</dependency>
<dependency>
<groupId>org.flyx.dsa.heldendokument</groupId>
<artifactId>generator</artifactId>
<version>0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.controlsfx</groupId>
<artifactId>controlsfx</artifactId>
<version>8.20.8</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>org.flyx.dsa.heldendokument.gui.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.1.2</version>
<configuration>
<mainClass>org.flyx.dsa.heldendokument.gui.App</mainClass>
<appName>DSA Heldendokument-Generator</appName>
<needMenu>false</needMenu>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>aboutWindow.fxml</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>aboutWindow.fxml</include>
</includes>
</resource>
</resources>
</build>
</project>
I'm the maintainer of the javafx-maven-plugin.
As far as I can see, there is nothing wrong with your pom.xml, maybe this already works when you upgrade the plugin-version to current 8.1.5 ?!
To make sure where some dependency come from, please call mvn dependency:tree, maybe it's your own dependency:
<dependency>
<groupId>org.flyx.dsa.heldendokument</groupId>
<artifactId>generator</artifactId>
<version>0.1-SNAPSHOT</version>
</dependency>
What confuses me: why are you putting "pluginManagement" inside your build instead just "plugins"?

IntelliJ Maven Selenium Build jar

I am using IntelliJ 12, Java 7, Selenium 2.31.0 and Maven. I can run my tests out of the IDE just fine but I am running into a problem trying to create a jar file. I can create the jar file double clicking on mvn clean and then double clicking install. All is well and the jar is created. The problem occurs when I go to run the jar via command line.
java -jar xyz-selenium-test-1.0.jar
Returns: Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver
I have added selenium-server-standalone-2.31.0.jar as a library in the project settings and as a dependency module in the project settings. I must be missing something in my pom file but I just don't know what it is. I have also attached my pom file as well.
<?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>com.xyz.selenium.test</groupId>
<artifactId>xyz-selenium-test</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>xyz-selenium-test</name>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.31.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>2.31.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-htmlunit-driver</artifactId>
<version>2.31.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>selenium-jar</groupId>
<artifactId>selenium-server-standalone-2.31.0.jar</artifactId>
<version>2.31.0</version>
<scope>system</scope>
<systemPath>/usr/local/selenium/selenium-server-standalone-2.31.0.jar</systemPath>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>2.31.0</version>
<exclusions>
<exclusion>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<index>true</index>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.setup.test.Setup</mainClass>
</manifest>
<manifestEntries>
<mode>development</mode>
<url>${project.url}</url>
<key>value</key>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
You have to add your dependencies to the classpath when you run your program:
java -cp "selenium-java.jar:..." -jar xyz-selenium-test-1.0.jar
Maven also allows you to run a Main class with all the required dependencies in the classpath (see option 1 in the previous link).
Otherwise you can create a Jar with dependencies, which will contain everything you need to run your code:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.setup.test.Setup</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
and run
java -jar xyz-selenium-test-jar-with-dependencies-1.0.jar
You can also use the OneJar plugin
<plugin>
<groupId>org.dstovall</groupId>
<artifactId>onejar-maven-plugin</artifactId>
<version>1.4.4</version>
<executions>
<execution>
<configuration>
<onejarVersion>0.97</onejarVersion>
<attachToBuild>true</attachToBuild>
<!-- Optional, default is "onejar" -->
<classifier>onejar</classifier>
</configuration>
<goals>
<goal>one-jar</goal>
</goals>
</execution>
</executions>
</plugin>

Categories

Resources