1

I'm trying to create a jar from my maven project containing the jar files from dependencies in a specific folder.

The framework I'm writing a plugin for requires external dependencies to be supplied as jar files in the plugin jar.

For example:

xxxx.jar
/myapp/myjavaclasses
/lib/externalDependencies.jar

My pom file:

<?xml version="1.0" encoding="UTF-8"?>
<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>AAAAA</groupId>
    <artifactId>BBBBBBB</artifactId>

    <packaging>jar</packaging>

    <version>1.1</version>
    <dependencies>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.8</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>

            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifestEntries>
                            <Rundeck-Plugin-Classnames>CCCCC</Rundeck-Plugin-Classnames>
                            <Rundeck-Plugin-Version>1.1</Rundeck-Plugin-Version>
                            <Rundeck-Plugin-Archive>true</Rundeck-Plugin-Archive>
                            <Rundeck-Plugin-File-Version>${project.version}</Rundeck-Plugin-File-Version>
                            <Rundeck-Plugin-Libs>lib/httpclient-4.5.8.jar lib/httpcore-4.4.11.jar</Rundeck-Plugin-Libs>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

        </plugins>
    </build>
</project>

In the above pom file we have the dependency

org.apache.httpcomponents

, this dependency contains the following jars

httpclient-4.5.8.jar httpcore-4.4.11.jar

these jars need to be imported in my final jar under the folder /lib.

M92
  • 56
  • 4
  • 1
    Have you checked [Building a fat jar using maven](https://stackoverflow.com/questions/16222748/building-a-fat-jar-using-maven)? – ernest_k Apr 12 '19 at 15:20
  • @ernest_k Yes, this solution includes all the class files from the dependencie, I need the jar files. – M92 Apr 12 '19 at 15:47
  • 1
    Then check [force Maven to copy dependencies into target/lib](https://stackoverflow.com/questions/97640/force-maven-to-copy-dependencies-into-target-lib). You can then `jar` the directory. – ernest_k Apr 12 '19 at 15:52
  • 1
    @ernest_k Thanks, combined the solution from the above post with resources! – M92 Apr 12 '19 at 16:16

1 Answers1

1

Thanks to @ernest_k came to a solution using

    <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>

and

<resources>
    <resource>
        <directory>.</directory>
        <includes>
            <include>lib/**/*.jar</include>
        </includes>
    </resource>
</resources>
M92
  • 56
  • 4