1. 新建项目目录 scala-java-mix

2. 创建 src 目录及子目录:

mkdir -p src/main/java
mkdir -p src/main/scala

3. 在目录 scala-java-mix 中创建 pom.xml文件,并添加下面内容到 pom.xml 文件

<?xml version="1.0" encoding="UTF-8"?>

<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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion>
<groupId>lasclocker</groupId>
<artifactId>scala-java-mix</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Scala-Java mixture</name>
<description>Showcase mixing Scala and Java</description>
<packaging>jar</packaging> <build>
<plugins>
<!-- ensure that we use JDK 1.6 -->
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin> <plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.15.2</version>
<executions>
<!-- Run scala compiler in the process-resources phase, so that dependencies on
scala classes can be resolved later in the (Java) compile phase -->
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution> <!-- Run scala compiler in the process-test-resources phase, so that dependencies on
scala classes can be resolved later in the (Java) test-compile phase -->
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin> <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<!-- Add src/main/scala to source path of Eclipse -->
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/scala</source>
</sources>
</configuration>
</execution> <!-- Add src/test/scala to test source path of Eclipse -->
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/test/scala</source>
</sources>
</configuration>
</execution>
</executions>
</plugin> <!-- to generate Eclipse artifacts for projects mixing Scala and Java -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
<projectnatures>
<projectnature>org.scala-ide.sdt.core.scalanature</projectnature>
<projectnature>org.eclipse.jdt.core.javanature</projectnature>
</projectnatures>
<buildcommands>
<buildcommand>org.scala-ide.sdt.core.scalabuilder</buildcommand>
</buildcommands>
<classpathContainers>
<classpathContainer>org.scala-ide.sdt.launching.SCALA_CONTAINER</classpathContainer>
<classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
</classpathContainers>
<excludes>
<!-- in Eclipse, use scala-library, scala-compiler from the SCALA_CONTAINER rather than POM <dependency> -->
<exclude>org.scala-lang:scala-library</exclude>
<exclude>org.scala-lang:scala-compiler</exclude>
</excludes>
<sourceIncludes>
<sourceInclude>**/*.scala</sourceInclude>
<sourceInclude>**/*.java</sourceInclude>
</sourceIncludes>
</configuration>
</plugin> <!-- When run tests in the test phase, include .java and .scala source files -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.8.1</version>
<configuration>
<includes>
<include>**/*.java</include>
<include>**/*.scala</include>
</includes>
</configuration>
</plugin>
</plugins>
</build> <dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.9.0</version>
</dependency>
</dependencies>
</project>

4. 在 eclipse 中 import 该项目,在目录 src/main/java 下创建 package,并编写 java 代码;在目录 src/main/scala 下创建 package,并编写 scala 代码

5. 即可分别运行 java 代码 和 scala 代码

在Eclipse中混合Java和Scala编程的更多相关文章

  1. eclipse中 将java项目转换为web项目

    来自:http://jadethao.iteye.com/blog/1331308 eclipse中 将java项目转换为web项目 1.找到项目工作空间目录,打开.project文件,并修改文件,  ...

  2. eclipse中添加Java代码注释模板

    eclipse中添加Java代码注释模板 1.Window->Preference->Java->Code Style->Code Template,进入注释编辑界面 2.文件 ...

  3. 在Eclipse中运行JAVA代码远程操作HBase的示例

    在Eclipse中运行JAVA代码远程操作HBase的示例 分类: 大数据 2014-03-04 13:47 3762人阅读 评论(2) 收藏 举报 下面是一个在Windows的Eclipse中通过J ...

  4. Eclipse中把Java工程修改成web工程

    Eclipse中把Java工程修改成web工程 点击项目:右击:选择properties--输入project facets,将“Dynamic Web Module”打勾即可:

  5. 沉淀再出发:如何在eclipse中查看java的核心代码

    沉淀再出发:如何在eclipse中查看java的核心代码 一.前言   很多时候我们在eclipse中按F3键打算查看某一个系统类的定义的时候,总是弹出找不到类这样的界面,这里我们把核心对应的代码加进 ...

  6. eclipse中运行java程序

    1 package ttt; public class Testttt { public static void main() { Person p =new Person(); p.name=&qu ...

  7. 在Eclipse中设置Java类上面的注释(包含作者、日期等)

    希望在Eclipse中,让Java类上面的注释像下面这样,改如何设置呢? 在Eclipse中,点击菜单中的Window-->Preferences,打开如下窗口:

  8. eclipse中,把java函数代码折叠/展开

    首先,在eclipse 中开启设置代码折叠功能 1. windows->perferences->General->Editors->Structured Text Edito ...

  9. eclipse中导入java类失败的问题

    在 Eclips 开发时,新建了一个 Dynamic Web Project,在运行jsp文件时tomcat报错: org.apache.jasper.JasperException: Unable ...

随机推荐

  1. P2380 狗哥采矿

    #include<iostream> #include<algorithm> #include<cstring> ; using namespace std; in ...

  2. jquery 数字滚动方法

    jquery 数字滚动方法用的是countUp.js这个插件 target = 目标元素的 ID:startVal = 开始值:endVal = 结束值:decimals = 小数位数,默认值是0:d ...

  3. Linux命令实战(二)

    1.printf格式化输出(format and print data) 语法:printf(选项)(参数) 参数 输出格式:指定数据输出时的格式: 输出字符串:指定要输出的数据. 格式替代符 %c ...

  4. nyoj 116 士兵杀敌(二)(线段树、单点更新)

    士兵杀敌(二) 时间限制:1000 ms  |  内存限制:65535 KB 难度:5   描述 南将军手下有N个士兵,分别编号1到N,这些士兵的杀敌数都是已知的. 小工是南将军手下的军师,南将军经常 ...

  5. HttpClient在高并发场景下的优化实战

    在项目中使用HttpClient可能是很普遍,尤其在当下微服务大火形势下,如果服务之间是http调用就少不了跟http客户端找交道.由于项目用户规模不同以及应用场景不同,很多时候可能不需要特别处理也. ...

  6. 编译k8s1.11 kube-apiserver源码

    说明 修改k8s1.11 kube-apiserver源码并构建成镜像,最终替换运行在集群中的kube-apiserver pod来验证本次源码修改 参看链接:https://xinchen.blog ...

  7. KubeCon 2019 北美会议完美落幕 | 云原生生态周报 Vol. 29

    作者 | 陈俊.张晓宇.徐迪 业界要闻 KubeCon 2019 北美会议召开 业界最隆重的盛会 KubeCon+CloudNativeCon 今年在圣地亚哥举办,超过 12000 名参会者以及 10 ...

  8. 2019-11-27:kali 2019-4中文乱码解决方法

    1.更换阿里源 vim /etc/apt/soul,编辑源之后,apt-get updata && apt-get upgrade && apt-get clean , ...

  9. ETL的两种架构——ETL架构和ELT架构优劣势对比

    ​ 导读: 作为现代企业和组织机构的重要资源,信息是进行科学管理与决策分析的基础.ETL 则是把数据转换为信息.知识的关键步骤之一.在 AI 应用场景下,数据集成有哪些特点?随着 AI 应用场景越来越 ...

  10. 构建调试Linux内核网络代码的环境MenuOS系统

    构建MenuOS系统 1.将指定文件拷贝到本地: git clone https://github.com/mengning/linuxnet.git 此过程可能需要输入github账号和密码. 2. ...