使用maven进行scala项目的构建

目标:
1、命令行用maven进行scala项目构建
2、产生eclipse项目文件

pom.xml文件

<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"> 	<groupId>com.xxx</groupId> 	<artifactId>xxx</artifactId> 	<version>1.0-SNAPSHOT</version> 	<modelVersion>4.0.0</modelVersion>   	<properties> 		<scala.version>2.8.1</scala.version> 	</properties>   	<build> 		<plugins> 			<plugin> 				<artifactId>maven-eclipse-plugin</artifactId> 				<configuration> 					<downloadSources>true</downloadSources> 					<buildcommands> 						<buildcommand>org.scala-ide.sdt.core.scalabuilder</buildcommand> 					</buildcommands> 					<projectnatures> 						<projectnature>org.scala-ide.sdt.core.scalanature</projectnature> 						<projectnature>org.eclipse.jdt.core.javanature</projectnature> 					</projectnatures> 					<classpathContainers> 						<classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer> 						<classpathContainer>org.scala-ide.sdt.launching.SCALA_CONTAINER</classpathContainer> 					</classpathContainers> 					<sourceIncludes> 						<sourceInclude>**/*.scala</sourceInclude> 					</sourceIncludes> 				</configuration> 			</plugin> 			<plugin> 				<groupId>org.scala-tools</groupId> 				<artifactId>maven-scala-plugin</artifactId> 				<executions> 					<execution> 						<goals> 							<goal>compile</goal> 							<goal>testCompile</goal> 						</goals> 					</execution> 				</executions> 			</plugin> 			<plugin> 				<groupId>org.codehaus.mojo</groupId> 				<artifactId>build-helper-maven-plugin</artifactId> 				<executions> 					<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> 					<execution> 						<id>add-test-source</id> 						<phase>generate-sources</phase> 						<goals> 							<goal>add-test-source</goal> 						</goals> 						<configuration> 							<sources> 								<source>src/test/scala</source> 							</sources> 						</configuration> 					</execution> 				</executions> 			</plugin> 		</plugins> 	</build> </project>

要点分析

	<properties> 		<scala.version>2.8.1</scala.version> 	</properties>

通过properties定义scala的版本
因为scala的版本是不兼容的,比如说2.8编译的class文件不能跟2.9的类库一起使用
这个定义同时会影响maven-scala-plugin中使用的scala版本
当然你也可以在dependencies中通过${scala.version}使用这个版本号

maven-eclipse-plugin部分是产生eclipse项目,对应使用scala-ide
打开downloadSources下载类库源代码,可以在eclipse中直接查看
sourceIncludes段必须加入,不然会出现代码目录中看不到scala文件的情况

maven-scala-plugin段用于命令行用maven进行构建

build-helper-maven-plugin段用于引入额外的代码目录
这个配置同时对命令行构建和eclipse项目生成有效
我这个是一个mixed Java/Scala项目

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值