0

I'm testing Spark using java and run into some problems when running my program using Eclipse.

The test code is the following :

package projet1;


import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;

public class projet1 {

    public static void main(String[] args) {
    System.out.println("Hello world");
    System.setProperty("hadoop.home.dir", "/home/user1/Spark_Projects");
    Logger.getLogger("org.apache").setLevel(Level.WARN);

    SparkConf conf = new SparkConf().setAppName("SiravPg").setMaster("local[*]");
    JavaSparkContext sc = new JavaSparkContext(conf);
    JavaRDD<String> myRDD = sc.textFile("src/main/ressources/data.txt")
    sc.close();
    }

}

When running this code, it seems that eclipse doesn't detect my main() function and displays a new Window asking me to Select a Java Application

Java Application

PS : The "System.out.println("Hello world");" is running correctly.

Aziz Azizos
  • 15
  • 1
  • 6
  • first of, why do you have a "final" keyword there? it makes no sense secondly, if the println runs correctly, that goes to show that not only is your main method found, but it runs – Stultuske Jan 21 '19 at 09:44
  • Println runs only if I comment all the remaining code and keep it alone, but with the rest of code included, nothing runs. – Aziz Azizos Jan 21 '19 at 09:49
  • https://stackoverflow.com/questions/19649949/java-eclipse-error-method-not-found-in-class – Kishore Jan 21 '19 at 09:58
  • @Kishore I tried all the solutions mentioned, with no luck – Aziz Azizos Jan 21 '19 at 11:04
  • Are you shure that Eclipse correctly compiles your class, if you have the spark stuff uncommented? Maybe try to separate the Main Method and the initialisation and start with the debugger... – keuleJ Jan 21 '19 at 12:31
  • Have you tried to add things step by step? like without the logging, etc. just to see what is actually the offending line. Second option: have you tried to run it though Maven? – jgp Jan 25 '19 at 13:34

2 Answers2

0

The solution for this issue is to select the class to run from the list displayed, in my case I select project1 and Click on OK button.

Aziz Azizos
  • 15
  • 1
  • 6
-1

Just use public static void main(String[] args) instead of public static void final main(String[] args).

vivekdubey
  • 484
  • 2
  • 7