Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure Maven build for Java project with external dependencies?

I'm trying to create automated solution for building with maven. My vision is to have a Maven build, which creates JAR file from my project and then just copies all the dependencies as JARs to some sub-directory in "target" folder.

I do not want to use Shade or Assembly (so I do not want to extract the content of other JARs and include it in one "super-JAR", because the project is more complicated and it breaks when I'm including all the JARs in one file).

How can I do such build POM?

like image 863
Miro Hudak Avatar asked Jan 15 '23 04:01

Miro Hudak


2 Answers

I don't see here any problem. Just create maven pom.xml with <packaging>jar</packaging> By default it should not pack into your jar all dependent libraries.

<plugin>
  <artifactId>maven-dependency-plugin</artifactId>
  <executions>
    <execution>
      <phase>install</phase>
      <goals>
        <goal>copy-dependencies</goal>
      </goals>
      <configuration>
        <outputDirectory>${project.build.directory}/lib</outputDirectory>
      </configuration>
    </execution>
  </executions>
</plugin>
like image 178
Igor Konoplyanko Avatar answered Jan 20 '23 16:01

Igor Konoplyanko


Related with your latest comment, use this plugin to add the main class in the manifest:

        <plugin>
            <!-- Build an executable JAR -->
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                        <mainClass>com.test.YourMainClass</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
like image 31
mrod Avatar answered Jan 20 '23 16:01

mrod