Scala:Java 项目中混入scala代码

斯帕克(Spark) 是用Scala代码写的。为了调试斯帕克,做了之类尝试。

 

1、Eclipse下:Java 项目 ,Using Maven,编写了一个java 版斯帕克应用。
斯帕克的代码(scala代码可以调节,可是查看变量极不方便,不忍直视,毕竟调试器时Java的,但代码是scala生成的字节码,如故有出入的)。

2、Scala IDE下:Scala 项目,Using Maven,编写一个Scala版的斯帕克应用。

报找不到类的非凡。解决该问题的点子是:http://scala-ide.org/docs/tutorials/m2eclipse/index.html

不难点说:

第一步:升级Maven插件

   因为Scala
IDE本事就是一个有Scala插件、Maven插件的Eclipse。不过放到的Maven插件只好创制Java项目,无法创建Scala项目。所以要立异Maven插件。

第二步:创建Maven项目时,选择scala的archetypes。

 

 

只是因为Scala IDE下载相关插件,速度其实是不敢恭维,就此作罢。

 

3、Scala IDE下:Java 项目,Using
Maven,编写Scala 版的Spark应用。

在pom.xml中配备
scala编译器,以使使用Maven构建时,会采用Scala相关的编译器对Scala代码举办编译,生成字节码。

那样一来,就足以行使Scala调试器举办调节了。

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.fjn.helper</groupId>
  <version>0.0.1-SNAPSHOT</version>
  <artifactId>frameworkex-apache-spark</artifactId>
  <name>frameworkex-apache-spark</name>
  <url>http://maven.apache.org</url>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <dependencies>
    <dependency>
        <groupId>org.apache.spark</groupId>
        <artifactId>spark-core_2.10</artifactId>
        <version>2.0.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.spark</groupId>
        <artifactId>spark-streaming_2.10</artifactId>
        <version>2.0.2</version>
    </dependency>
    <dependency>
        <groupId>org.scala-lang</groupId>
        <artifactId>scala-library</artifactId>
        <version>2.10.6</version>
    </dependency>

  </dependencies>
    <build>
        <plugins>
            <!-- This plugin compiles Scala files -->
            <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>

            <!-- This plugin compiles Java files -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <!-- This plugin adds all dependencies to JAR file during 'package' command.
            Pay EXTRA attention to the 'mainClass' tag.
            You have to set name of class with entry point to program ('main' method) -->

            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.5.3</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>sparkTest1</mainClass>
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

 

相关文章