Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include external jars in maven jar build process?

Tags:

I want to build a .jar file with dependencies in maven. Unfortunately I have to include some external .jars in my buildpath. When I now try to build this project with maven package I will get an error that those external .jars are not found.

How to adapt my pom file to add those jars? current:

    <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/classes/lib</outputDirectory>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>false</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.2-beta-4</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
    </plugins>
like image 769
Matthias Kricke Avatar asked Sep 12 '12 08:09

Matthias Kricke


People also ask

How can I add external jar in spring boot?

There are two simple ways to do that: the simplest one is to add the property on the command line. Also, you will not launch the Spring Boot application in the usual format (java -jar application). On the other hand, you will launch the PropertiesLauncher class but adding in the classpath your Spring Boot application.


2 Answers

You can include the external jars in your build path as dependency with <scope>system</scope> .

Check this link

like image 95
basiljames Avatar answered Sep 19 '22 16:09

basiljames


You need use below command to add external jar into .m2 folder

mvn install:install-file -Dfile=[JAR] -DgroupId=[some.group] -DartifactId=[Some Id] -Dversion=1.0.0 -Dpackaging=jar

This will add the given jar in to your .m2 folder. After that go to pom.xm and just add the dependency with given group id, artifact id and version.

like image 29
Nirbhay Rana Avatar answered Sep 16 '22 16:09

Nirbhay Rana