博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Getting Started with Erlang
阅读量:6224 次
发布时间:2019-06-21

本文共 6642 字,大约阅读时间需要 22 分钟。

Getting Started with Erlang

is a great language that lets you build highly concurrent applications. This tutorial will teach you how to quickly get started with it.

In this section:

Preliminary steps

Installing Erlang OTP

The first thing for setting up an Erlang environment is installing Erlang OTP, a set of Erlang libraries essential for development.

Windows

If you are a Windows user, download the and run the installation wizard. Once the installation is over, add the installation path plus \bin to the PATH environment variable.

OS X

If you are an OS X user, to install Erlang OTP, type the following at the Terminal prompt (make sure you have installed on your machine):

brew install erlang

Note that if you prefer to Homebrew, your command line should be different:

port install erlang +ssl

Linux

The installation process for Linux is similar to OS X, except that instead of “brew” or “port” you have to use “apt-get” (a Linux package management utility):

apt-get install erlang

Note that you can always the latest version of Erlang OTP package for any OS.

Verifying Erlang OTP installation

To verify that Erlang OTP is installed correctly, run the Erlang shell by typing erl in a Terminal prompt:

erlang_otp

To learn more about the Erlang shell, you can read its .

Installing Rebar

In addition to Erlang OTP, you’ll also need , a build tool that helps compile and test Erlang applications. The easiest way to install it on your machine is to download its sources and build it locally:

git clone git://github.com/rebar/rebar.git $ cd rebar $ ./bootstrap Recompile: src/getopt ... Recompile: src/rebar_utils ==> rebar (compile)

Congratulations! You now have a self-contained script called "rebar" in your current working directory. Place this script anywhere in your path and you can use rebar to build OTP-compliant apps.

Setting up IntelliJ IDEA

Now when Erlang OTP and Rebar are set up, it’s time to and IntelliJ IDEA. Keep in mind, that for Erlang development you can use IntelliJ IDEA Community Edition (which is free and open-source).

Once the IDE is up and you see its , go to Configure | Plugins, then click Browse repositories, locate the Erlang plugin and install it:

erlang_plugin

After installing the plugin, restart IntelliJ IDEA.

Configuring an Erlang SDK

One more thing you’ll have to do to configure IntelliJ IDEA is to add an Erlang SDK.

To do that, change the structure of the default project. Open the default project structure in one of the two ways:

  • On the , go to Configure | Project Defaults | Project Structure
  • On the main menu, choose File | Other Settings | Default Project Structure

Then, add an Erlang SDK by specifying the path to the Erlang OTP installation directory.

erlang_sdk

If you don’t know where Erlang OTP was installed, check the following directories:

  • Windows: C:\Program Files\erl<version>
  • Linux: /usr/lib/erlang/<version>
  • MacPorts, OS X: /opt/local/lib/erlang/<version>
  • Homebrew, OS X: /usr/local/Cellar/erlang/<version>

Configuring Rebar

The final adjustment you have to do is to specify the path to Rebar, so that IntelliJ IDEA can run Rebar commands from the IDE.

You can do it via Configure | Preferences | Other Settings → Erlang External Tools:

erlang_rebar_configure

path:输入  /usr/local/bin/   即可

Creating a new project

Creating an Erlang project

There are several ways to a new Erlang project. The easiest one is to use the from the Welcome screen.

Click Create New Project:

erlang_create_new_project

Then choose Erlang in the left pane, and click Next.

erlang_create_new_project_erlang

IntelliJ IDEA prompts you to choose an Erlang SDK (which you've already configured):

erlang_create_new_project_sdk

After that you’ll be asked to specify the name of your project and its directory. The following image shows the resulting Erlang project with the name ErlangDemo:

erlang_project

Creating a Rebar project

Instead of a pure Erlang project, you might want to create a project. To do that, type the following code at the Terminal prompt:

rebar create-app appid=<project name>

Once the project has been created, it into IntelliJ IDEA to make it possible to open this project in the IDE.

Importing a project into IntelliJ IDEA

You can a project into IntelliJ IDEA in several ways. Let's explore importing from the Welcome screen.

To import an existing project into IntelliJ IDEA, click Import on the Welcome Screen, and choose the project directory. IntelliJ IDEA offers you to either import the project from existing sources, or from an external model (a build file).

If your project uses Rebar, select the corresponding option when asked.

erlang_import_project

When importing a Rebar project, make sure to enable the option Fetch dependencies with rebar:

erlang_import_project_fetch

Running and debugging an application

To run an application, you have to created against the stub Erlang Application. To do this, on the main menu choose Run | Edit Configurations, select the stub Erlang Application, specify the name (here it is hello.hello_world), and specify the application’s module and function:

erlang_run_config

After that you’ll be able to run your application via the main menu (Run | Run <run configuration name>, the toolbar (run), or a even a shortcut (⌃⇧R).

Once you have a run/debug configuration, you can also debug your application via the main menu (Run | Debug ‘<run configuration name>, the toolbar (debug), or a shortcut (⌃D):

erlang_debug

For more information, refer to the and the procedural sections and .

Running Eunit tests

Running Eunit tests is similar to running an application, but needs a different run/debug configuration, created against the stub Erlang Eunit:

erlang_eunit_config

IntelliJ IDEA provides a handy with support for . It shows test results, lets you rerun tests of you choice, jump to failed tests, etc.:

erlang_test

Running Rebar commands

Running Rebar commands is also possible right from the IDE – with the help of the Erlang Rebar run/debug configuration:

erlang_rebar_run_config

Note that if your Rebar commands run tests, you can use a Erlang Rebar Eunit run/debug configuration to see test results in a Test Runner.

Additional

Learning Erlang

To learn Erlang, we recommend you to start by reading the , and of course the tutorial by .

Learning IntelliJ IDEA

IntelliJ IDEA is a Java IDE in the first place, however it’s also a platform and IDE for other languages, such as Erlang, Python, Ruby, PHP, and many other. To learn more about IntelliJ IDEA, it’s worth checking out the and watch the .

If you have a question, you can always ask it on (probably it’s already answered).

Providing Feedback

In case you’d like to share your feedback about IntelliJ IDEA or its support for Erlang, feel free to submit an issue in , or to the .

Refer to the section .

 IntelliJ IDEA 比 Sublime 好用多了 哈哈  习惯了vs 和 xcode 还是 IntelliJ IDEA 顺手 !!!!!

https://www.jetbrains.com/idea/help/getting-started-with-erlang.html

 
 

转载于:https://www.cnblogs.com/jasonduan/p/5175445.html

你可能感兴趣的文章
eclipse.ini参数的含义和设置
查看>>
VirtualBox中常用的网络设置
查看>>
用 GetEnvironmentVariable 获取常用系统环境变量
查看>>
手把手安装ZABBIX2.2(CentOS6.5+Zabbix2.2.2)
查看>>
推送通知(本地推送+远程推送)详解
查看>>
ifconfig
查看>>
电子商务风险防控
查看>>
Android列表展示和手指滑动分页
查看>>
我的友情链接
查看>>
final 关键字修饰类、属性、方法的使用
查看>>
字符数组"student a am i"--》"i am a student"
查看>>
更改zabbix数据库mandatory
查看>>
使用Cocos Studio UI编辑器并在cocos2dx中加载
查看>>
对MYSQL进行压力测试
查看>>
运维自动化之 Cobbler 系统安装使用详解
查看>>
yii2 日志功能使用记录
查看>>
Cordova学习笔记 将Cordova项目连接远程服务器
查看>>
数据结构和算法05 之红-黑树
查看>>
find 搜索命令
查看>>
Redis分布式锁实现
查看>>