`
Mr.Chris
  • 浏览: 83138 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Maven配置:在Java工程中混入Scala

阅读更多

 

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<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>
			<sourceInclude>**/*.java</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>
			<configuration>
				<args>
					<arg>-encoding</arg>
					<arg>GBK</arg>
				</args>
				<includes>
					<!-- Don't have the scala compiler consider *.java files. -->
					<include>**/*.scala</include>
				</includes>
			</configuration>
		</execution>
	</executions>
</plugin>
<plugin>
	<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.codehaus.mojo</groupId>
	<artifactId>build-helper-maven-plugin</artifactId> <version>1.7</version>
	<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>

 

 

同时增加对scala-library的依赖:

 

<dependency>
	<groupId>org.scala-lang</groupId>
	<artifactId>scala-library</artifactId>
	<version>2.9.2-SNAPSHOT</version>
</dependency>

 

 

接着创建src/main/scala和src/test/scala目录即可。

 

如果你的工程使用GBK编码的,记住一定要加上上面红色表示的配置,否则会报如下错误:

[ERROR] error: IO error while decoding ... with UTF-8

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics