maven混合编译java&scala
Posted 拱头
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了maven混合编译java&scala相关的知识,希望对你有一定的参考价值。
步骤:
1. mvn 生成scala项目 mvn archetype:generate \\-DarchetypeGroupId=org.scala-tools.archetypes \\
-DarchetypeArtifactId=scala-archetype-simple \\
-DremoteRepositories=http://scala-tools.org/repo-releases 或 参考 笔记 《Idea+Maven创建scala项目》
2.添加java目录,添加完后,在IDEA中目录结构如下:
3.修改pom.xml文件 删除:
在<build><plugins>下增加maven插件: <plugin>
<groupId> org.codehaus.mojo </groupId>
<artifactId> build-helper-maven-plugin </artifactId>
<version> 1.9.1 </version>
</plugin>
4.直接使用package打包,打包结果如下图:
5.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" >
<modelVersion> 4.0.0 </modelVersion>
<groupId> com.tcl.bigdata.yhb </groupId>
<artifactId> java-scala-practice </artifactId>
<version> 1.0-SNAPSHOT </version>
<name> $project.artifactId </name>
<description> My wonderfull scala app </description>
<inceptionYear> 2010 </inceptionYear>
<properties>
<scala.version> 2.10.4 </scala.version>
<spark.version> 1.4.1 </spark.version>
<hadoop.version> 2.2.0 </hadoop.version>
<hbase.version> 0.98.7-hadoop2 </hbase.version>
</properties>
<repositories>
<repository>
<id> scala-tools.org </id>
<name> Scala-Tools Maven2 Repository </name>
<url> http://scala-tools.org/repo-releases </url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId> org.apache.hbase </groupId>
<artifactId> hbase-client </artifactId>
<version> $hbase.version </version>
<exclusions>
<exclusion>
<groupId> com.google.guava </groupId>
<artifactId> guava </artifactId>
</exclusion>
<exclusion>
<groupId> io.netty </groupId>
<artifactId> netty </artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId> org.apache.hbase </groupId>
<artifactId> hbase-server </artifactId>
<version> $hbase.version </version>
<exclusions>
<exclusion>
<groupId> org.mortbay.jetty </groupId>
<artifactId> servlet-api-2.5 </artifactId>
</exclusion>
<exclusion>
<groupId> com.sun.jersey </groupId>
<artifactId> jersey-core </artifactId>
</exclusion>
<exclusion>
<groupId> com.sun.jersey </groupId>
<artifactId> jersey-server </artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId> org.scala-lang </groupId>
<artifactId> scala-library </artifactId>
<version> $scala.version </version>
</dependency>
<dependency>
<groupId> junit </groupId>
<artifactId> junit </artifactId>
<version> 4.4 </version>
<scope> test </scope>
</dependency>
<dependency>
<groupId> org.specs </groupId>
<artifactId> specs </artifactId>
<version> 1.2.5 </version>
<scope> test </scope>
</dependency>
<dependency>
<groupId> org.apache.spark </groupId>
<artifactId> spark-core_2.10 </artifactId>
<version> $spark.version </version>
<exclusions>
<exclusion>
<artifactId> hadoop-client </artifactId>
<groupId> org.apache.hadoop </groupId>
</exclusion>
<exclusion>
<artifactId> hadoop-core </artifactId>
<groupId> org.apache.hadoop </groupId>
</exclusion>
<exclusion>
<artifactId> guava </artifactId>
<groupId> com.google.guava </groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId> org.apache.spark </groupId>
<artifactId> spark-sql_2.10 </artifactId>
<version> $spark.version </version>
</dependency>
<dependency>
<groupId> org.apache.spark </groupId>
<artifactId> spark-hive_2.10 </artifactId>
<version> $spark.version </version>
</dependency>
<dependency>
<groupId> org.apache.spark </groupId>
<artifactId> spark-mllib_2.10 </artifactId>
<version> $spark.version </version>
</dependency>
<dependency>
<groupId> org.apache.hadoop </groupId>
<artifactId> hadoop-client </artifactId>
<version> $hadoop.version </version>
<exclusions>
<exclusion>
<artifactId> guava </artifactId>
<groupId> com.google.guava </groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId> org.apache.hadoop </groupId>
<artifactId> hadoop-common </artifactId>
<version> $hadoop.version </version>
<exclusions>
<exclusion>
<artifactId> guava </artifactId>
<groupId> com.google.guava </groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId> mysql </groupId>
<artifactId> mysql-connector-java </artifactId>
<version> 5.1.37 </version>
</dependency>
<dependency>
<groupId> com.google.guava </groupId>
<artifactId> guava </artifactId>
<version> 14.0.1 </version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId> org.scala-tools </groupId>
<artifactId> maven-scala-plugin </artifactId>
<executions>
<execution>
<goals>
<goal> compile </goal>
<goal> testCompile </goal>
</goals>
</execution>
</executions>
<configuration>
<scalaVersion> $scala.version </scalaVersion>
<args>
<arg> -target:jvm-1.7 </arg>
</args>
</configuration>
</plugin>
<plugin>
<groupId> org.apache.maven.plugins </groupId>
<artifactId> maven-eclipse-plugin </artifactId>
<configuration>
<downloadSources> true </downloadSources>
<buildcommands>
<buildcommand> ch.epfl.lamp.sdt.core.scalabuilder </buildcommand>
</buildcommands>
<additionalProjectnatures>
<projectnature> ch.epfl.lamp.sdt.core.scalanature </projectnature>
</additionalProjectnatures>
<classpathContainers>
<classpathContainer> org.eclipse.jdt.launching.JRE_CONTAINER </classpathContainer>
<classpathContainer> ch.epfl.lamp.sdt.launching.SCALA_CONTAINER </classpathContainer>
</classpathContainers>
</configuration>
</plugin>
<plugin>
<groupId> org.codehaus.mojo </groupId>
<artifactId> build-helper-maven-plugin </artifactId>
<version> 1.9.1 </version>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId> org.scala-tools </groupId>
<artifactId> maven-scala-plugin </artifactId>
<configuration>
<scalaVersion> $scala.version </scalaVersion>
</configuration>
</plugin>
</plugins>
</reporting>
</project>
以上是关于maven混合编译java&scala的主要内容,如果未能解决你的问题,请参考以下文章