[英]Integrating both Java and Scala into one project
我對Java及其Spring框架非常熟悉。 因此,我們正在使用spring boot項目,其中我們已經使用java實現了各種服務,現在我們想在其中添加一些scala服務(用於spark實現)。
這樣我就可以輕松處理來自控制器(由UI提交)的請求。
任何人都可以提出一些我可以遵循的不同方法或最佳實踐來構建項目和創建服務
如果您可以通過一些示例或用例進行說明,那將是非常有用的。
我經常將Java和Scala混合使用的方法是基於Maven的。 將scala編譯器插件放在pom.xml
Maven編譯器插件上方:
<sourceDirectory>src/main/java</sourceDirectory>
<!--<testSourceDirectory>src/test/scala</testSourceDirectory>-->
<pluginManagement>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.4.1</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<configuration>
<recompileMode>incremental</recompileMode>
</configuration>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
<configuration>
<args>
<arg>-Ydelambdafy:method</arg>
<arg>-target:jvm-1.8</arg>
<arg>-deprecation</arg>
<arg>-feature</arg>
<arg>-unchecked</arg>
<arg>-language:implicitConversions</arg>
<arg>-language:postfixOps</arg>
</args>
</configuration>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<args>
<arg>-Ydelambdafy:method</arg>
<arg>-target:jvm-1.8</arg>
<arg>-deprecation</arg>
<arg>-feature</arg>
<arg>-unchecked</arg>
<arg>-language:implicitConversions</arg>
<arg>-language:postfixOps</arg>
</args>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<compilerId>javac</compilerId>
<debug>true</debug>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.