0

here is a basic file which I have created with Scala on Maven:

    package scala

class Example{
    val SparkVersion: String = org.apache.spark.SPARK_VERSION

    def showVersion(): Unit ={
        println("This project uses the following Spark version: " + SparkVersion)
    }
}
object MyTask {

    def main(args: Array[String]) = {
        val NewTask = new Example()
        NewTask.showVersion()
    }
}

The result is: "This project uses the following Spark version: 2.2.0"

pom.xml file contains the following plugins:

 <build>
    <sourceDirectory>src/main</sourceDirectory>
    <testSourceDirectory>src/test</testSourceDirectory>
    <plugins>
        <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.8.2</version>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
                <configuration>
                    <archive>
                        <manifestFile>Example.jar/META-INF/MANIFEST.MF</manifestFile>
                        <manifest>
                            <addClassPath>true</addClassPath>
                            <mainClass>src.main.scala.Example.MainClass</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

.jar file path is: C:\Users...\src\main\T29_2\out\artifacts\Example_jar\Example.jar

Here is how I tried to run this file on cmd, and what kind of errors I have received:

C:\Windows\System32> scala Example.jar 
Exception in thread "main" java.io.FileNotFoundException: Example.jar (The system cannot find the file specified)

C:\Windows\System32> scala C:\Users\...\src\main\T29_2\out\artifacts\Example_jar\Example.jar
java.lang.NullPointerException

C:\Windows\System32>java -jar C:\Users\...\src\main\T29_2\out\artifacts\Example_jar\Example.jar
no main manifest attribute, in C:\Users\...\src\main\T29_2\out\artifacts\Example_jar\Example.jar

Please help me to understand which actions I have to make in order to run this damn .jar file.

  • Can you look at this [question](https://stackoverflow.com/questions/6758258/running-a-maven-scala-project)? In mainClass you have to specify package + main class, so in your case something like scala.MyTask – WoAiNii Apr 25 '20 at 19:37

1 Answers1

0
  1. Correct your path to main class . It should .
<mainClass>scala.Example.MainClass</mainClass>
  1. Execute your jar using java cmd
java -cp C:\Users\...\src\main\T29_2\out\artifacts\Example_jar\Example.jar
QuickSilver
  • 3,915
  • 2
  • 13
  • 29
  • Hi, I have done step 1, re-built the .jar and tried step2. Here is what I have received: Unrecognized option: - Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. – EstherMallow Apr 26 '20 at 07:39
  • https://www.ghacks.net/2014/05/22/fix-error-create-java-virtual-machine-windows/ Please also verify the steps mentioned over here – QuickSilver Apr 26 '20 at 08:16