There are a lot of posts about this error. Some of them worthy to mention are one two. But I think my case is different my main class is running before adding dependencies in XML and soon as I do that I get error Error: Could not find or load main class example.test123
I followed this video link to try basic example in Scala using Spark.I did following:
Step 1: Created the simple project testalpha
Step 2: a) Right click on the project name>> Go to configure>> Add scala nature
b) Copy the XML code from maven-repository paste this in pom.xml
file. Not to forget to right click on Scala Library Container and change scala version to 2.10.6
Step 3: Add a folder scala
such that we have src/main/scala
Step 4: Create a package example
under src/main/scala
. In this package Create a simple scala object and define main
method to print hello
. My question is:
If I don't add any dependencies in XML. It prints hello
. But as soon as I add the dependencies I get this error Error: Could not find or load main class example.test123
.
Does anyone have any idea about this?
Screenshot to show project structure:
Screenshot showing printing of
hello
<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>com.scalaproject</groupId>
<artifactId>testalpha</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>testalpha</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.10</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Code Snippet:
package example
object test123 {
def main(args: Array[String]): Unit = {
print("Hello")
}
}