0

I'm not a very experienced Java user in terms of compilation with maven, eclipse, etc...

I'm trying to build a small proyect with some maven dependencies, and my idea is to include all the dependencies in the ganarated Jar.

This is the content of my pom.xml:

<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>amgrd</groupId>
  <artifactId>testFlink</artifactId>
  <packaging>jar</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>testFlink</name>
  <description>testFlink</description>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <flink.version>0.10.0</flink.version>
    <jdk.version>1.8</jdk.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.apache.flink</groupId>
        <artifactId>flink-java</artifactId>
        <version>${flink.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.flink</groupId>
        <artifactId>flink-streaming-java</artifactId>
        <version>${flink.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.flink</groupId>
        <artifactId>flink-clients</artifactId>
        <version>${flink.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.flink</groupId>
        <artifactId>flink-connector-kafka_2.11</artifactId>
        <version>0.10.0</version>
    </dependency>
</dependencies>

<build>
    <sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>

            <configuration>
                <archive>
                    <manifestEntries>
                        <Main-Class>StreamingWordCount</Main-Class>
                    </manifestEntries>
                </archive>
          <descriptorRefs>
              <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>${jdk.version}</source>
                <target>${jdk.version}</target>
            </configuration>
        </plugin>
    </plugins>
</build>
</project>

I splitted it on three parts to remark the piece of XML that should be configuring the project to include the jars in the generated file.

Then I show the context menu of the project and click on Run as... -> Maven --> And I type the target "package".

The generated jar does not contain dependencies, only pom.xml, manifest and my source code classes.

Thank you in advance

dhalfageme
  • 1,444
  • 4
  • 21
  • 42

1 Answers1

0

There should be two jars in your target directory after you build. One that only contains your classes, and one with all the classes. The latter has the suffix jar-with-dependencies.jar.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
  • There's only one JAR file, the one without dependencies. However now someone helped me to change the file and the one with dependencies is now generated, I will post now the difference between them when I figured out the reason why now it is working. Thanks – dhalfageme Aug 20 '19 at 08:46