-1

I want to add jars, from another folder to my main jar at runtime, to make main jar lightweight. How to do it? I am using maven. I thought about scope provided, but I don't know how to add these jars.

./lib/hikari.jar
./lib/h2.jar                        ./
===============                 =============
=             =                 =           =
=  Hikari.jar =                 =           =
=             =     --------->  =  Main.jar =
=  h2.jar     =                 =           =
=             =                 =           =
===============                 =============
korallo
  • 87
  • 2
  • 8

1 Answers1

0

It depends how you are making the jar.

You can do the following, use maven-dependency-plugin to copy your libs and then configure the maven-jar-plugin to use the libs from the classpath, no need to change the scope of the dependencies.

<plugin>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
              <goal>copy-dependencies</goal>
            </goals>
            <configuration>
              <outputDirectory>${project.build.directory}/lib</outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-jar-plugin</artifactId>
  <version>3.2.0</version>
  <configuration>
    <archive>
      <manifest>
        <addClasspath>true</addClasspath>
        <classpathPrefix>lib/</classpathPrefix>
        <mainClass>your.main.Class</mainClass>
        <useUniqueVersions>false</useUniqueVersions>
      </manifest>
    </archive>
  </configuration>
</plugin>
jeanpic
  • 481
  • 3
  • 15