Tuesday, July 18, 2017

JAVA and Scala Errors

1. For maven build errors:

In POM.xml add
 <build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
      <resource>
        <directory>src</directory>
        <excludes>
          <exclude>**/*.java</exclude>
        </excludes>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
    </plugins>
  </build>

2. For the error:

Exception in thread "main" java.lang.UnsupportedClassVersionError: Sparkjobs/Wordcount : Unsupported major.minor version 52.0


In Ecllipse,
Window -> Preferences -> Scala ->Compiler -> target Lower to jvm-1.7

3. In case of class not found exception for scala JAR,

In Ecllipse,
Window -> Preferences -> JAVA->Compiler -> compiler compliance level to jvm-1.7

4. In case of,

Unable to locate the Javac Compiler in:   C:\Program Files\Java\jre1.8.0_101\..\lib\tools.jar Please ensure you are using JDK 1.4 or above and not a JRE (the com.sun.tools.javac.Main class is required)

See if JDK 1.8.0 is installed if not install it.

Try updating the JDK Eclipse is using, as follows:
Add and set the JRE in Window->Preferences...->Java->Installed JREs:
JRE type: Standard VM JRE 
Name: jdk1.6.0_18
JRE home directory: C:\Program Files (x86)\Java\jdk1.6.0_18
https://stackoverflow.com/questions/2222560/maven-build-failed-unable-to-locate-the-javac-compiler-in-jre-or-jdk-issue

5. In spark streaming job, if encountered the below error:

ERROR streaming.StreamingContext: Error starting the context, marking it as stopped
org.apache.kafka.common.config.ConfigException: Missing required configuration "bootstrap.servers" which has no default value.

Then modify metadata.broker.list to "bootstrap.servers"

in case of similar errors like "value.deserializer" or "key.deserializer" 

    val kafkaParams = Map("bootstrap.servers" -> brokers,
                        "key.deserializer" -> classOf[StringDeserializer],
                        "value.deserializer" -> classOf[StringDeserializer])

6. To run a JAR:
2 Options:
1. Add main class in Manifest file
2. Include Manifest in POM.xml
https://stackoverflow.com/questions/9689793/cant-execute-jar-file-no-main-manifest-attribute

Run using command:
java -cp consumerTest-0.0.1-SNAPSHOT.jar consumerTest.KafkaConsumer

7. To configure settings for compiling maven via command prompt:
configure java for windows https://stackoverflow.com/questions/1672281/environment-variables-for-java-installation
MVN clean install

8. To include all the dependencies in the Jar file, follow 
In case of error,
 Exception in thread "PollableSourceRunner-KafkaSource-kafka-source" java.lang.NoSuchMethodError: scala.Predef$.ArrowAssoc(Ljava/lang/Object;)Ljava/lang/Object;

This occurred because of missing dependencies on the machine JAR is being executed.
Package all the Jars into the deployed jar.
https://stackoverflow.com/questions/1729054/including-dependencies-in-a-jar-with-maven. This would PACKAGE all the dependant jars inside single JAR


9. In case of any function call giving error because of mismatched input arguments then look for the appropriate imports.

10. Java Decompiler can be installed in Ecllipse follow: http://jd.benow.ca/

2 comments: