简体   繁体   中英

Eclipse Maven Build Is not Including Dependencies on Generated Jar File

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM