0001 @echo off
0002
0003 rem
0004 rem Licensed to the Apache Software Foundation (ASF) under one or more
0005 rem contributor license agreements. See the NOTICE file distributed with
0006 rem this work for additional information regarding copyright ownership.
0007 rem The ASF licenses this file to You under the Apache License, Version 2.0
0008 rem (the "License"); you may not use this file except in compliance with
0009 rem the License. You may obtain a copy of the License at
0010 rem
0011 rem http://www.apache.org/licenses/LICENSE-2.0
0012 rem
0013 rem Unless required by applicable law or agreed to in writing, software
0014 rem distributed under the License is distributed on an "AS IS" BASIS,
0015 rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0016 rem See the License for the specific language governing permissions and
0017 rem limitations under the License.
0018 rem
0019
0020 rem Figure out where the Spark framework is installed
0021 call "%~dp0find-spark-home.cmd"
0022
0023 call "%SPARK_HOME%\bin\load-spark-env.cmd"
0024
0025 rem Test that an argument was given
0026 if "x%1"=="x" (
0027 echo Usage: spark-class ^<class^> [^<args^>]
0028 exit /b 1
0029 )
0030
0031 rem Find Spark jars.
0032 if exist "%SPARK_HOME%\jars" (
0033 set SPARK_JARS_DIR="%SPARK_HOME%\jars"
0034 ) else (
0035 set SPARK_JARS_DIR="%SPARK_HOME%\assembly\target\scala-%SPARK_SCALA_VERSION%\jars"
0036 )
0037
0038 if not exist "%SPARK_JARS_DIR%"\ (
0039 echo Failed to find Spark jars directory.
0040 echo You need to build Spark before running this program.
0041 exit /b 1
0042 )
0043
0044 set LAUNCH_CLASSPATH=%SPARK_JARS_DIR%\*
0045
0046 rem Add the launcher build dir to the classpath if requested.
0047 if not "x%SPARK_PREPEND_CLASSES%"=="x" (
0048 set LAUNCH_CLASSPATH="%SPARK_HOME%\launcher\target\scala-%SPARK_SCALA_VERSION%\classes;%LAUNCH_CLASSPATH%"
0049 )
0050
0051 rem Figure out where java is.
0052 set RUNNER=java
0053 if not "x%JAVA_HOME%"=="x" (
0054 set RUNNER=%JAVA_HOME%\bin\java
0055 ) else (
0056 where /q "%RUNNER%"
0057 if ERRORLEVEL 1 (
0058 echo Java not found and JAVA_HOME environment variable is not set.
0059 echo Install Java and set JAVA_HOME to point to the Java installation directory.
0060 exit /b 1
0061 )
0062 )
0063
0064 rem The launcher library prints the command to be executed in a single line suitable for being
0065 rem executed by the batch interpreter. So read all the output of the launcher into a variable.
0066 :gen
0067 set LAUNCHER_OUTPUT=%temp%\spark-class-launcher-output-%RANDOM%.txt
0068 rem SPARK-28302: %RANDOM% would return the same number if we call it instantly after last call,
0069 rem so we should make it sure to generate unique file to avoid process collision of writing into
0070 rem the same file concurrently.
0071 if exist %LAUNCHER_OUTPUT% goto :gen
0072 "%RUNNER%" -Xmx128m -cp "%LAUNCH_CLASSPATH%" org.apache.spark.launcher.Main %* > %LAUNCHER_OUTPUT%
0073 for /f "tokens=*" %%i in (%LAUNCHER_OUTPUT%) do (
0074 set SPARK_CMD=%%i
0075 )
0076 del %LAUNCHER_OUTPUT%
0077 %SPARK_CMD%