Changing an application core built in Java to Scal

2019-09-15 22:22发布

问题:

Imagine 2 modules for an application. One is called core and acts like an API with a set of interfaces (and some functions defined).

The other module is called CoreTest and implements some classes that extend the API and tests are made in that core using JUnit.

Now I want to change only the core module to Scala. And I am a rooky at scala :).

So far I got an error:

The project was not built since its build path is incomplete. Cannot find the class file for scala.collection.immutable.List. Fix the build path then try building this project ScalaCoreTest

So that raised some doubts.

  • Can I use strucutures defined by Scala for Scala?
  • Should I avoid using other things in scala that can't be "translated" to Java?

I am using eclipse with scala plugin.

回答1:

Check if the standard Scala library is included in your project. Right-click the project in the Package Explorer, choose Properties, Java Build Path, Libraries.

You should see at least a JRE System Library and a Scala Library there.

Your project is probably lacking the Scala Library. Add it by clicking the "Add Library..." button on the right, select "Scala Library", and click Finish.



回答2:

Right click on the project and select "Configure > Add Scala Nature". This will configure your build path correctly.