We were creating a Maven project having packaging type jar. We had main class from where we were starting project execution. It was working fine through Eclipse but when we created jar file by compiling with Maven, we were not able to run the jar as it was throwing missing dependencies errors.
Maven provides a plugin named Maven-assembly-plugin which is used to pack all dependencies while creating jar file.
Add plugin in
<plugin> <artifactId>Maven-assembly-plugin</artifactId> <version>2.4</version> <configuration> <archive> <manifest> <mainClass>main class path here</mainClass> </manifest <manifestEntries> <Class-Path>.</Class-Path> </manifestEntries> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> <executions> <execution> <id>make-assembly</id> <!-- this is used for inheritance merges -> <phase>package</phase> <!-- bind to the packaging phase --> <goals> <goal>single>/goal> </goals> </execution> </executions> </plugin>
After adding this plugin, it packs all required libraries (declared inside pom.xml file) in the final jar file.
Webner Solutions is a Software Development company focused on developing CRM apps (Salesforce, Zoho), LMS Apps (Moodle/Totara), Websites and Mobile apps. If you need Web development or any other software development assistance please contact us at firstname.lastname@example.org