I'm in a situation where I need to build a fat jar from a multi module maven project. The project is built based on Selenium/cucumber API's.
Structure of my project is as follows
Parent -- pom
|
|__core_module src/main/java --> helper classes for selenium
|
|__acme_module src/main/test --> Test Classes for acme project
I have tried different ways to build a "acme_test.jar" which includes core_module+acme_module.But none of them helped me.
Much appreciate any clue to solve this .
Thanks
You can produce a jar which will include your test classes and resources. To reuse this artifact in an other project, you must declare this dependency with type test-jar : <project>
Maven can build a Fat JAR from your Java project. A Fat JAR is a single JAR file that contains all the compiled Java classes from your project, and all compiled Java classes from all JAR files your project depends on (see Maven Dependencies).
In the "Package-Explorer" (not the "Resource-View") right click on the project "demolib". Select "+ Build Fat Jar". A Configuration Dialog appears. Just press "Finish".
As @MariuszS mentions, first restructure your project so that you separate any Unit tests or integration tests for the actual classes that test (=drive/verify navigation for) Acme.
Parent -- pom
|
|__core_module src/main/java --> helper classes for selenium
|
|__acme_module src/main/java --> Classes specific for navigating acme
|
|__acme_module src/test/java--> (Unit etc) Test Classes for acme project
Then, you need acme_module to contain core_module as dependency.
Finally, in acme_module, put this in your build plugins section:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<id>create-fat-jar</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<!-- add Main-Class to manifest file -->
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>your.main.class</mainClass>
</transformer>
</transformers>
<finalName>YourJarName</finalName>
</configuration>
</execution>
</executions>
</plugin>
You can also explicitly include the core_module by adding an include filter in the plugin configuration section
Configure acme_module
as fat module - this module should produce executable fat jar with all dependencies.
Add core_module
to acme_module
as dependency.
Move your test classes from src/test/java
to src/main/java
, because this class should be executable. If you have tests (like junit), then leave this classes inside test
directory, but executable part should stay in main
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With