9653

Apache Flink: java.lang.NoClassDefFoundError

<h3>Question</h3>

I'm trying to follow this example but when I try to compile it, I have this error:

Error: Unable to initialize main class com.amazonaws.services.kinesisanalytics.aws Caused by: java.lang.NoClassDefFoundError: org/apache/flink/streaming/api/functions/source/SourceFunction

The error is due this code:

private static DataStream<String> createSourceFromStaticConfig(StreamExecutionEnvironment env) { Properties inputProperties = new Properties(); inputProperties.setProperty(ConsumerConfigConstants.AWS_REGION, region); inputProperties.setProperty(ConsumerConfigConstants.STREAM_INITIAL_POSITION, "LATEST"); return env.addSource(new FlinkKinesisConsumer<>(inputStreamName, new SimpleStringSchema(), inputProperties)); }

And I suppose this is the problematic line:

return env.addSource(new FlinkKinesisConsumer<>(inputStreamName, new SimpleStringSchema(), inputProperties));

This are my maven dependencies:

What could be wrong? any dependencies, version?

Note: If I comment the problematic line, the program run without problem.

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>as</groupId> <artifactId>a</artifactId> <version>1</version> <packaging>jar</packaging> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <geotools.version>21-SNAPSHOT</geotools.version> <java.version>1.8</java.version> <scala.binary.version>2.11</scala.binary.version> <flink.version>1.6.2</flink.version> <kda.version>1.0.1</kda.version> </properties> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>${java.version}</source> <target>${java.version}</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>3.0.0</version> <executions> <!-- Run shade goal on package phase --> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <artifactSet> <excludes> <exclude>org.apache.flink:force-shading</exclude> <exclude>com.google.code.findbugs:jsr305</exclude> <exclude>org.slf4j:*</exclude> <exclude>log4j:*</exclude> </excludes> </artifactSet> <filters> <filter> <!-- Do not copy the signatures in the META-INF folder. Otherwise, this might cause SecurityExceptions when using the JAR. --> <artifact>*:*</artifact> <excludes> <exclude>META-INF/*.SF</exclude> <exclude>META-INF/*.DSA</exclude> <exclude>META-INF/*.RSA</exclude> </excludes> </filter> </filters> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <mainClass>com.amazonaws.services.kinesisanalytics.aws</mainClass> </transformer> </transformers> </configuration> </execution> </executions> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>org.locationtech.jts</groupId> <artifactId>jts-core</artifactId> <version>1.16.0</version> </dependency> <dependency> <groupId>org.geotools</groupId> <artifactId>gt-geojson</artifactId> <version>${geotools.version}</version> </dependency> <dependency> <groupId>org.geotools</groupId> <artifactId>gt-geojsondatastore</artifactId> <version>${geotools.version}</version> </dependency> <dependency> <groupId>org.geotools</groupId> <artifactId>gt-main</artifactId> <version>${geotools.version}</version> </dependency> <dependency> <groupId>com.amazonaws</groupId> <artifactId>aws-kinesisanalytics-runtime</artifactId> <version>${kda.version}</version> </dependency> <dependency> <groupId>org.apache.flink</groupId> <artifactId>flink-connector-kinesis_${scala.binary.version}</artifactId> <version>${flink.version}</version> </dependency> <dependency> <groupId>org.apache.flink</groupId> <artifactId>flink-streaming-java_${scala.binary.version}</artifactId> <version>${flink.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.amazonaws</groupId> <artifactId>aws-kinesisanalytics-flink</artifactId> <version>${kda.version}</version> </dependency> </dependencies> </project>
<h3>Answer1:</h3>

Your error is here:

<dependency> <groupId>org.apache.flink</groupId> <artifactId>flink-streaming-java_${scala.binary.version}</artifactId> <version>${flink.version}</version> <scope>provided</scope> </dependency>

The scope is provided. This means, that your program expects that library to be accessible during runtime, but it can't find it nowhere.

NoClassDefFound means it was accessible for compile time, but not during the execution.

Change the scope to compile in order to resolve this issue. Also, you can take a look here for more technical info.

来源:https://stackoverflow.com/questions/54106187/apache-flink-java-lang-noclassdeffounderror

Recommend

  • Graphql, how to return empty array instead of null
  • How can I save Array of Class Objects in to a Plist(Iphone Development)
  • Unicode File IO in Codename One
  • apache zeppelin is started but there is connection error in localhost:8080
  • When i select a Textfield the keyboard moves over it
  • Eric5: The OK button of 'new project' dialog is disable
  • Jekyll - How do I create pages in the root directory?
  • Making Django.contrib.auth store plain-text password
  • create circular Auto Horizontal Scroll View?
  • Converting bitmap to byte and vice versa
  • didSelectItemAtIndexPath of UICollectionView inside of a UIScrollView is not getting called
  • How do you run a synchronous timer in C#?
  • How to display converted time zones in a 'generic week' (Sunday thru Saturday)?
  • Arraylist of strings into one comma separated string
  • Facebook Error (#200) The user hasn't authorized the application to perform this action (PHP)
  • Building JavaFX 2.0 App on Mac, deploying on Windows
  • Create an Office365 mailbox from within C# Web API method
  • Julia 1.0 UndefVarError - Scope of Variable
  • Query takes almost two seconds but matches only two rows - why isn't the index helping?
  • How to load dynamic images in custom ListView
  • How to make Rss News Reader application in android …? [closed]
  • What is the difference between dynamically creating a script tag and statically embed a script tag?
  • Add font awesome icon to custom add to cart button in Woocommerce 3
  • How to merge objects within array based on attribute
  • how to read to huge file into buffer
  • Create an average of multiple excel chart without the data source
  • Typeahead.js does give me suggestions but doesn't select them
  • using maven pom while creating jar:test-jar some times it says JAR will be empty - no content was ma
  • I am consuming a WCF service that requires headers from a .NET 2 website. How can I programmatically
  • how to get the location(lat/lng) on google maps v3 from the location(x,y)
  • how to run ejabberd with Erlang on Heroku?
  • How to use Streams api peek() function and make it work?
  • `$http:badreq Bad Request Configuration` - from angular post method, what is wrong here?
  • How to handle div that is created dynamically in a table
  • Google App Engine backend servlet not responding
  • Sign a Pdf using custom digital signature in Java
  • How to use FirstOrDefault inside Include
  • media foundation H264 decoder not working properly
  • How to mutate multiple variables without repeating codes?
  • Time Complexity of Fibonacci Algorithm [duplicate]