Integrating Scala into an existing project in Java

后端 未结 4 500
闹比i
闹比i 2020-12-29 22:40

we have a project written in Java. It is a maven project, that has jsp pages and a lot of java code:

  • servlets for handling user requests and dealing out respon
4条回答
  •  长情又很酷
    2020-12-29 23:20

    I work on a mixed Java/Scala project right now (previously a Java-only project). Remember, there is no difference as far as the JVM is concerned between a .class file generated from javac vs. one generated from scalac.

    For example: I implement Java interfaces and extend Java classes in Scala with no problems. I also instantiate Java beans and 'Scala' spring beans together in the same definition file (with scala beans having dependencies on java beans and vice-versa), and I have both Java and Scala beans coexisting together in a spring integration messaging pipeline.

    The two languages inter-operate quite well, though where collections are concerned, you'll probably want to take a look at Scala's JavaConversions and JavaConverters objects.

    For building, we use Ant (I'd personally prefer SBT for a new project, but if you're dealing with a pre-existing java project that uses ant, it's likely to be more trouble than it's worth to change build systems). To configure ant to compile scala files, have a look at this question.

提交回复
热议问题