您的位置:首页 > 编程语言 > Java开发

Eclipse Maven 构建Java和Scala混合项目

2016-11-13 11:26 435 查看
一,Eclipse 安装Maven 插件

可以到Eclipse Maket去搜索

二,安装scala插件

     1,新的scala插件可以在Eclipse Maket搜索安装;

     2,要想安装旧的,比如scala2.10.4插件,就要下载,Eclipse scala离线安装插件:Help->Install New SoftWare->add->local,选择本地插件地址

三、配置Ecipse Maven插件的远程Archetype库:windows->preference->Maven->Archetype->add
Remote Catalog,在catalog file输入:http://repo1.maven.org/maven2/archetype-catalog.xml,这是maven中央仓库的archetype-catalog地址:

四、new->maven->maven project->选择刚刚新建的catalog,然后搜索scala,选择scala-archetype-simple

五、修改新建Maven项目的pom文件。添加scala-maven-plugin

例如:

<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>bigData-Study</groupId>

  <artifactId>bigData-Study</artifactId>

  <version>0.0.1-SNAPSHOT</version>

  <name>${project.artifactId}</name>

  <description>My wonderfull scala app</description>

  <inceptionYear>2015</inceptionYear>

  <licenses>

    <license>

      <name>My License</name>

      <url>http://....</url>

      <distribution>repo</distribution>

    </license>

  </licenses>

  <properties>

    <maven.compiler.source>1.6</maven.compiler.source>

    <maven.compiler.target>1.6</maven.compiler.target>

    <encoding>UTF-8</encoding>

    <scala.version>2.10.4</scala.version>

    <scala.compat.version>2.10</scala.compat.version>

  </properties>

  <dependencies>

<!--     <dependency> -->

<!--       <groupId>org.scala-lang</groupId> -->

<!--       <artifactId>scala-library</artifactId> -->

<!--       <version>${scala.version}</version> -->

<!--     </dependency> -->

    <!-- Test -->

    <dependency>

      <groupId>junit</groupId>

      <artifactId>junit</artifactId>

      <version>4.11</version>

      <scope>test</scope>

    </dependency>

    <dependency>

      <groupId>org.specs2</groupId>

      <artifactId>specs2-core_${scala.compat.version}</artifactId>

      <version>2.4.16</version>

      <scope>test</scope>

    </dependency>

    <dependency>

      <groupId>org.scalatest</groupId>

      <artifactId>scalatest_${scala.compat.version}</artifactId>

      <version>2.2.4</version>

      <scope>test</scope>

    </dependency>

  </dependencies>

  <build>

    <sourceDirectory>src/main/scala</sourceDirectory>

    <testSourceDirectory>src/test/scala</testSourceDirectory>

<pluginManagement>

    <plugins>

      <plugin>

        <!-- see http://davidb.github.com/scala-maven-plugin -->

        <groupId>net.alchim31.maven</groupId>

        <artifactId>scala-maven-plugin</artifactId>

        <version>3.2.0</version>

        <executions>

          <execution>

            <goals>

              <goal>compile</goal>

              <goal>testCompile</goal>

            </goals>

            <configuration>

              <args>

                <arg>-make:transitive</arg>

                <arg>-dependencyfile</arg>

                <arg>${project.build.directory}/.scala_dependencies</arg>

              </args>

            </configuration>

          </execution>

        </executions>

      </plugin>

      <plugin>

        <groupId>org.apache.maven.plugins</groupId>

        <artifactId>maven-surefire-plugin</artifactId>

        <version>2.18.1</version>

        <configuration>

          <useFile>false</useFile>

          <disableXmlReport>true</disableXmlReport>

          <!-- If you have classpath issue like NoDefClassError,... -->

          <!-- useManifestOnlyJar>false</useManifestOnlyJar -->

          <includes>

            <include>**/*Test.*</include>

            <include>**/*Suite.*</include>

          </includes>

        </configuration>

      </plugin>

        <plugin>

            <groupId>org.apache.maven.plugins</groupId>

            <artifactId>maven-archetype-plugin</artifactId>

<!--             <version>2.2</version> -->

        </plugin>

        <plugin>  

                    <groupId>org.apache.maven.plugins</groupId>  

                    <artifactId>maven-compiler-plugin</artifactId>  

<!--                     <configuration>   -->

<!--                         <source>1.5</source>   -->

<!--                         <target>1.5</target>   -->

<!--                     </configuration>   -->

                </plugin>  

                <plugin>  

                    <groupId>org.apache.maven.plugins</groupId>  

                    <artifactId>maven-resources-plugin</artifactId>  

                    <configuration>  

                        <encoding>UTF-8</encoding>  

                    </configuration>  

                </plugin>  

    </plugins>

    </pluginManagement>

  </build>

</project>

六、自己新建src/main/java等source folder,结构如下
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: