最新消息:非无江海志,潇洒送日月

在ubuntu之下使用eclipse和java开发Spark应用的方法

编程开发 江海志 7714浏览 0评论

It is assumed that you have installed java JDK.  I am currently using JDK 1.7

Download the Eclipse luna and untar it to an /opt/ directory as a sudo

cd /opt/ && sudo tar -zxvf ~/Downloads/eclipse-*.tar.gz

Then, to add a shortcut, create a new file

sudo gedit /usr/share/applications/eclipse.desktop

in gedit, write the following lines, save and exit:

[Desktop Entry]

Name=Eclipse 4

Type=Application

Exec=/opt/eclipse/eclipse

Terminal=false

Icon=/opt/eclipse/icon.xpm

Comment=Integrated Development Environment

NoDisplay=false

Categories=Development;IDE;

Name[en]=Eclipse

Open eclipse under applications->programming.

When done, create a new Maven project by doing:

File->new->Project

Under Maven dropdown, select “Maven Project” then click on Next.

Select:
Create simple project ….
Use Default Workspace….
Click Next

Select ANYTHING for a groupID and ArtifactID then press FInish

Then go to a Project Explorer
Click on the root (name) of the project
Go to help->install new software->add…
The URL is  http://download.scala-ide.org/sdk/lithium/e44/scala211/stable/site
For name use anything (Scala)
Select all suggestions and install them.

Under Package Explorer, double-click on the pom.xml

Locate the Dependencies tab and click on it

Click on Add… under the Dependencies and type

groupId: org.apache.spark
artifactId: spark-core_2.10
version: 1.2.0

Save and close the POM file’s tab.

in Package explorer, right click on src/main/java and select new class.
Make a new class with a main, you can call it  NewClass

Copy and paste the code below

import org.apache.spark.SparkConf ;
import org.apache.spark.api.java.JavaSparkContext;

public class NewClass {
public static void main(String[]args){
SparkConf conf = new SparkConf (). setMaster ( “local” ). setAppName ( “My App” );
JavaSparkContext sc = new JavaSparkContext ( conf );
}
}

Press run, the project will build and run

IF YOU GET AN ERROR:
Exception in thread “main” java.lang.NoClassDefFoundError: scala/Cloneable…
just import the  Maven project from below (sorry):

https://drive.google.com/file/d/0B7egWfChXyoebTlvRHFiNUMzZWc/view?usp=sharing

转载请注明:江海志の博客 » 在ubuntu之下使用eclipse和java开发Spark应用的方法

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址