scalamavenscala-maven-plugin

scala-maven-plugin : ClassNotFoundException


I am trying to run a simple Scala Hello World program using scala-maven-plugin from the command line in my Ubuntu VM running in Win-7 host OS.

I tried to execute in the following two ways :-

  1. mvn scala:run -DmainClass=com.infoobjects.HelloWorld

  2. Declaring the main class in a launcher tag in pom.xml and then executing mvn scala:run from the command line

But I am getting ClassNotFoundException in either case.

Directory Structure :-

Project > src > main > scala > com > infoobjects > HelloWorld.scala

Thanks in advance.

Here's my pom.xml

<build>
    <finalName>sparkplay</finalName>
    <plugins>
        <plugin>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>scala-maven-plugin</artifactId>
            <configuration>
        <launchers>
        <launcher>
        <id>launcher1</id>
        <mainClass>com.infoobjects.HelloWorld</mainClass>
        </launcher>
        </launchers>
            <executions>
                <execution>
                    <id>scala-compile-first</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>add-source</goal>
                        <goal>compile</goal>
                    </goals>
                </execution>
                <execution>
                    <id>scala-test-compile</id>
                    <phase>process-test-resources</phase>
                    <goals>
                        <goal>testCompile</goal>
                    </goals>
                </execution>
            </executions>
            </configuration>
        </plugin>
    </plugins>
</build>

Solution

  • your pom.xml has schema's issue : <executions> should not be child of <configuration>. So everything under <executions> is ignored

    see Maven Model