Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8835991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:23:23+00:00 2026-06-14T09:23:23+00:00

I have a java maven project that I want to unit test with scala.

  • 0

I have a java maven project that I want to unit test with scala. But how can I mix java and scala code within the one Eclipse project since java and scala uses their own compilers. Because of this scala code will not compile in Eclipse since the java compiler expects java syntax.

Currently my projects are based on Eclipse and they are java based projects. Do they need to be converted to a different project type such a scala ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:23:24+00:00Added an answer on June 14, 2026 at 9:23 am

    If you want to just test Java code from Scala then it is quite easy to set up such a maven project. Since I am not an eclipse user I am not sure how it works with eclipse. I have tested with IntelliJ and it works very well. Shouldn’t be any problems with eclipse either.

    I created a simple pom.xml that just uses the scala compiler for the tests and uses the normal java compiler for the main java code.

    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>com.stackoverflow.Q13379591</groupId>
        <artifactId>Q13379591</artifactId>
        <version>1.0-SNAPSHOT</version>
    
        <name>${project.artifactId}-${project.version}</name>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <scala.version>2.9.2</scala.version>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.scala-lang</groupId>
                <artifactId>scala-library</artifactId>
                <version>${scala.version}</version>
            </dependency>
            <dependency>
                <groupId>org.scalatest</groupId>
                <artifactId>scalatest_${scala.version}</artifactId>
                <version>2.0.M4</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.scala-tools</groupId>
                    <artifactId>maven-scala-plugin</artifactId>
                    <version>2.15.2</version>
                    <executions>
                        <execution>
                            <id>scala-test-compile</id>
                            <phase>test-compile</phase>
                            <goals>
                                <goal>testCompile</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <args>
                            <arg>-g:vars</arg>
                            <arg>-make:transitive</arg>
                            <arg>-dependencyfile</arg>
                            <arg>${project.build.directory}/.scala_dependencies</arg>
                        </args>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.scalatest</groupId>
                    <artifactId>scalatest-maven-plugin</artifactId>
                    <version>1.0-M2</version>
                    <configuration>
                        <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
                        <junitxml>.</junitxml>
                        <filereports>WDF TestSuite.txt</filereports>
                        <stdout>W</stdout> <!-- Skip coloring output -->
                    </configuration>
                    <executions>
                        <execution>
                            <id>scala-test</id>
                            <goals>
                                <goal>test</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </project>
    

    Now here’s a simple Java class that I want to test:

    src/main/java/com/stackoverflow/Hello.java

    package com.stackoverflow;
    
    /**
     * @author maba, 2012-11-14
     */
    public interface Hello {
        String hello();
    }
    

    src/main/java/com/stackoverflow/HelloJava.java

    package com.stackoverflow;
    
    /**
     * @author maba, 2012-11-14
     */
    public class HelloJava implements Hello {
    
        public String hello() {
            return "Hello Java";
        }
    }
    

    And finally the ScalaTest test class.

    src/test/scala/com/stackoverflow/HelloJavaTest.scala

    package com.stackoverflow
    
    import org.scalatest.FlatSpec
    
    /**
     * @author maba, 2012-11-14
     */
    class HelloJavaTest extends FlatSpec {
      "HelloJava" should "be instance of Hello" in {
        val hello = new HelloJava
        val result = hello match {
          case f:Hello => true
        }
        assert(result)
      }
    
      it should "say Hello Java" in {
        val helloJava = new HelloJava
        assert(helloJava.hello === "Hello Java")
      }
    }
    

    You can now run it with this command:

    mvn test
    

    I can just right click on the test case in IntelliJ and run the test. It should be possible in eclipse as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java multi-module Maven project that I want to build an MVN
I have a few Java/Maven projects that I want to use in a Grails
I have a Java application that is managed using Maven. The project involves the
I have a fairly simple maven-ized Java project, but am having trouble getting my
I have a Java project that is built using Maven , thus my build
I have one jar dependency in my java project that contains sources as well
I downloaded Java source code of some project that works with Maven. After checking
I have a Java Maven project that I developed a while ago and that
I have a maven Java project (Project A) which depends on a second project
I have a Maven Java project, imported using m2eclipse . The target/ directory is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.