I am new to Apache Spark and testing my first program.
It is a 2-3 lines program just for testing purposes.
I am using Eclipse and compiled the java file with Maven.
I am trying to run the spark-submit but getting this error.
I do not think it is from the file name or the path.
Could it be from another issue?
...spark-2.1.0-bin-hadoop2.7\\bin>spark-submit --class "Main" --master local[4] "C:\\Users\\...\\target\\SparkTest-0.0.1-SNAPSHOT.jar"
The filename, directory name, or volume label syntax is incorrect.
This is the main class
import java.util.Arrays;
import org.apache.spark.api.java.JavaPairRDD;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.SparkConf;
import org.apache.spark.SparkContext;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.FlatMapFunction;
import org.apache.spark.api.java.function.PairFunction;
public class SparkMain {
public static void main(String[] args) {
SparkConf conf = new SparkConf().setMaster("local").setAppName("My App");
JavaSparkContext sc = new JavaSparkContext(conf);
System.out.println("HELLO");
JavaRDD<String> lines = sc.textFile("C:/spark/spark-2.1.0-bin-hadoop2.7/README.md");
System.out.println(lines.count());
}
}
You are passing a String to a Java program and on a Windows machine.
Windows uses backslashes and need to be escaped.
I'm on a Mac, so this is hard to test, but you could try something like this.
import java.nio.file.Paths;
...
String fileName = Paths.get("C:", "spark", "spark-2.1.0-bin-hadoop2.7", "README.md").toString()
JavaRDD<String> rdd = sc.textFile(fileName);
System.out.println(rdd.count());
If you want to be cross-platform, then perhaps this
String rootDir = Paths.get(System.getProperty("user.home")).getRoot().toString();
String fileName = Paths.get(rootDir, "spark", ...);
...
Refer: Java Essentials | Path Operations
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.