Maven build not exporting dependent library's for packaging type jar

Sumit Ghosh :

I need to create a runnable jar file that will be operated in Batch mode. During development I need to use following api/frameworks apache-poi,hibernate,Spring etc.

So,I prefer to go with maven:

Please find below my maven file:

<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>mypackage</groupId>
    <artifactId>myartifact</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>
    <properties>
       <java.version>1.8</java.version>
    </properties>
   <dependencies>
      <dependency>
         <groupId>org.hibernate</groupId>
         <artifactId>hibernate-core</artifactId>
         <version>5.2.17.Final</version>
      </dependency>
      <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>spring-context</artifactId>
         <version>5.0.6.RELEASE</version>
      </dependency>
      <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>spring-orm</artifactId>
         <version>5.0.6.RELEASE</version>
     </dependency>
     <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>spring-jms</artifactId>
         <version>5.0.6.RELEASE</version>
     </dependency>
     <dependency>
          <groupId>org.apache.poi</groupId>
          <artifactId>poi</artifactId>
          <version>3.17</version>
      </dependency>
      <dependency>
         <groupId>org.apache.commons</groupId>
         <artifactId>commons-lang3</artifactId>
         <version>3.8.1</version>
      </dependency>
     </dependencies>
    <build>
      <plugins>
         <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-jar-plugin</artifactId>
              <configuration>
                  <archive>
                      <manifest>
                          <addClasspath>true</addClasspath>
                       <mainClass>fully.qualified.classpath.Main</mainClass>
                       </manifest>
                       <manifestEntries>
                         <Class-Path>.</Class-Path>
                      </manifestEntries>
                   </archive>
              </configuration>
           </plugin>
       </plugins>
   </build>
 </project>

I am running the maven build from eclipse as clean package. Build completes successfully.But in the generated jar all the dependent jar is not present [spring/hibernate/poi] etc.

We need to run this jar as java -jar jarname from command prompt/console.

matejko219 :

Consider using Maven Shade Plugin.

This plugin provides the capability to package the artifact in an uber-jar, including its dependencies

Spring framework can do similar thing for you. Generate sample project and check its pom file.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=135346&siteId=1