Maven构建java和scala混编项目

Mixed Java/Scala Projects

The scala-maven-plugin is used for compiling/testing/running/documenting scala code in maven.

 分别设置好source folder :src/main/java,src/test/java,src/main/scala,src/test/scala

然后设置 pom 的dependences ,以及build中的内容即可。

详见:http://davidb.github.io/scala-maven-plugin/example_compile.html

setup

Place java sources files in :

src/main/java

Place java test sources files in :

src/test/java

Place scala sources files in :

src/main/scala

Place scala test sources files in :

src/test/scala

Make your pom file look similar to the following (this is what we use for integration testing):

          
<?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>sandbox</groupId>
	<artifactId>testJavaAndScala</artifactId>
	<version>1.0-SNAPSHOT</version>
	<name>Test for Java + Scala compilation</name>
	<description>Test for Java + Scala compilation</description>

	<dependencies>
		<dependency>
			<groupId>org.scala-lang</groupId>
			<artifactId>scala-library</artifactId>
			<version>2.10.6</version>
		</dependency>
	</dependencies>

	<build>
		<pluginManagement>
			<plugins>
				<plugin>
					<groupId>net.alchim31.maven</groupId>
					<artifactId>scala-maven-plugin</artifactId>
					<version>3.2.1</version>
				</plugin>
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-compiler-plugin</artifactId>
					<version>2.0.2</version>
				</plugin>
			</plugins>
		</pluginManagement>
		<plugins>
			<plugin>
				<groupId>net.alchim31.maven</groupId>
				<artifactId>scala-maven-plugin</artifactId>
				<executions>
					<execution>
						<id>scala-compile-first</id>
						<phase>process-resources</phase>
						<goals>
							<goal>add-source</goal>
							<goal>compile</goal>
						</goals>
					</execution>
					<execution>
						<id>scala-test-compile</id>
						<phase>process-test-resources</phase>
						<goals>
							<goal>testCompile</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<executions>
					<execution>
						<phase>compile</phase>
						<goals>
							<goal>compile</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>

</project>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
下面是搭建idea+maven+spark+scala项目的步骤: 1. 安装JDK和Scala环境。 2. 安装Maven。 3. 在IDEA中创建Maven项目。 4. 在pom.xml文件中添加依赖,包括SparkScala相关依赖。 5. 在src/main/scala目录下创建Scala文件。 6. 编写Spark程序。 7. 运行程序。 具体步骤如下: 1. 安装JDK和Scala环境 首先需要安装Java开发工具包(JDK),并配置环境变量。然后安装Scala编程语言,同样也需要配置环境变量。可以参考官网的安装说明进行操作。 2. 安装Maven Maven是一个Java项目管理工具,可以自动下载所需的依赖库,并将项目打包成Jar包。可以从官网下载Maven,并配置环境变量。 3. 在IDEA中创建Maven项目 在IDEA中创建Maven项目,选择Scala模板,填写项目名称、groupId、artifactId等信息。IDEA会自动生成pom.xml文件。 4. 在pom.xml文件中添加依赖 在pom.xml文件中添加SparkScala相关依赖,例如: ``` <dependencies> <dependency> <groupId>org.apache.spark</groupId> <artifactId>spark-core_2.11</artifactId> <version>2.4.5</version> </dependency> <dependency> <groupId>org.apache.spark</groupId> <artifactId>spark-sql_2.11</artifactId> <version>2.4.5</version> </dependency> <dependency> <groupId>org.scala-lang</groupId> <artifactId>scala-library</artifactId> <version>2.11.8</version> </dependency> </dependencies> ``` 5. 在src/main/scala目录下创建Scala文件 在src/main/scala目录下创建Scala文件,例如: ``` object Test { def main(args: Array[String]) { val conf = new SparkConf().setAppName("Test").setMaster("local[*]") val sc = new SparkContext(conf) val sqlContext = new SQLContext(sc) val df = sqlContext.read.json("data/people.json") df.show() } } ``` 6. 编写Spark程序 在Scala文件中编写Spark程序,例如读取JSON文件并显示数据。 7. 运行程序 在IDEA中运行程序,即可看到Spark程序的输出结果。 以上就是搭建idea+maven+spark+scala项目的步骤。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

mtj66

看心情

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值