3

I am trying to use maven to handle dependencies in a scala project in Eclipse. But once the project is converted to maven, the application wont run anymore.

Here is the steps to reproduce :

1) new scala project

  • project name : test
  • finish

2) new scala object

  • name : hello_world
  • finish

3) hello_world.scala

package test

object hello_world {
  def main(args: Array[String]) {
    println("Hello world !!!")
  }
}

4) run scala application

  • project : test
  • main class : test.hello_world

result : working, hello world is printed

5) right clic on project -> configure -> convert to mavem project

  • group id : test
  • artifact id : test
  • version : 0.0.1-SNAPSHOT
  • packaging : jar
  • finish

6) run scala application

  • project : test
  • main class : test.hello_world

result :

Error: Could not find or load main class test.hello_world

Versions details :

Eclipse 4.4.1 M2E 1.5.0 Scala IDE for Eclipse 4.0.0.nightly-2_11

Generated pom-xml :

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>test</groupId>
  <artifactId>test</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
      <resource>
        <directory>src</directory>
        <excludes>
          <exclude>**/*.java</exclude>
        </excludes>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
1
  • Do you have m2eclipse-scala installed? Does your maven build work correctly from the command line (i.e. you have the maven scala plugin configured)? You may need to manually configure the project as a scala project: right click, configure, add scala nature. Commented Nov 14, 2014 at 14:39

4 Answers 4

3

http://scala-tools.org/repo-releases is deprecated, here is a working pom.xml :

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>

<repositories>
    <repository>
        <id>scala-tools.org</id>
        <name>Scala-tools Maven2 Repository</name>
        <url>https://oss.sonatype.org/content/groups/scala-tools/</url>
    </repository>
</repositories>

<pluginRepositories>
    <pluginRepository>
        <id>scala-tools.org</id>
        <name>Scala-tools Maven2 Repository</name>
        <url>https://oss.sonatype.org/content/groups/scala-tools/</url>
    </pluginRepository>
</pluginRepositories>

<dependencies>
    <dependency>
        <groupId>org.scala-lang</groupId>
        <artifactId>scala-library</artifactId>
        <version>2.11.4</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <sourceDirectory>src</sourceDirectory>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>maven-scala-plugin</artifactId>
                <version>3.2.0</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
            </plugin>
        </plugins>
    </pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.scala-tools</groupId>
            <artifactId>maven-scala-plugin</artifactId>
            <executions>
                <execution>
                    <id>scala-compile-first</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>add-source</goal>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

</project>

To run the application :

run -> scala application

  • project : test
  • main class : test.hello_world
Sign up to request clarification or add additional context in comments.

Comments

1

Your pom.xml should contain these parts (change the versions of course):

Repositories:

    <repositories>
        <repository>
            <id>scala-tools.org</id>
            <name>Scala-Tools Maven2 Repository</name>
            <url>http://scala-tools.org/repo-releases</url>
        </repository>
    </repositories>

Plugin repositories:

<pluginRepositories>
    <pluginRepository>
        <id>scala-tools.org</id>
        <name>Scala-Tools Maven2 Repository</name>
        <url>http://scala-tools.org/repo-releases</url>
    </pluginRepository>
</pluginRepositories>

Dependencies:

<dependencies>
    <dependency>
        <groupId>org.scala-lang</groupId>
        <artifactId>scala-library</artifactId>
        <version>${scala.version}</version>
    </dependency>
</dependencies>

Build:

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.scala-tools</groupId>
                <artifactId>maven-scala-plugin</artifactId>
                <version>2.15.2</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
            </plugin>
        </plugins>
    </pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.scala-tools</groupId>
            <artifactId>maven-scala-plugin</artifactId>
            <executions>
                <execution>
                    <id>scala-compile-first</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>add-source</goal>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Comments

1

Go to

project properties->Select scala compiler->Select scala installation and change to scala-2.10->apply->close

Run

     maven clean

Run Scala application

then you cant see the output in Console

Comments

0

May be mine is late reply but it may help some one, Below process fixed my issue.

Please do check whether your source folders is on build path or not. If your source folders is not in build path you can't see run as scala application in runas

To add your source to build path 1) Right click on project properties 2) In left side pane select Java Build Path and in source tab click on add folder and select your source folder and click ok

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.