title: “开发环境准备” lang: cn ref: setup-develop-environment permalink: /cn/developers/setup-develop-environment/ excerpt: “开发环境准备” last_modified_at: 2017-06-24T18:48:43+08:00

{% include toc %}

基本环境准备

在您开始前,请确保以下应用已安装:

Git配置

  1. 注册Github。由于ServiceComb的代码是托管在Github上的,所以您需要有一个Github的帐号,可前往 https://github.com/join?source=header-home 进行注册,如您已有Github帐号,则可跳过此步。注册完成后直接在 https://github.com/login?return_to=%2Fjoin%3Fsource%3Dheader-home 进行登录即可。

  2. 配置Git。主要配置Git的个人信息和设置免密码提交代码。个人信息可通过以下指令进行配置:

    git config --global user.name <your-user-name>
    git config --global user.email <your-email-address>
    

    其中,请将<your-user-name>和<your-email-address>替换为您在Github上注册用到的用户名和邮箱信息。设置免密码提交代码可参考Git免密码提交代码教程{:target=“_blank”}。

  3. 获取项目代码。以 ServiceComb-Java-Chassis 项目为例,可直接执行以下指令获取代码:

    git clone https://github.com/apache/servicecomb-java-chassis.git
    

IDE 环境配置

现有支持Java开发的IDE很多,如Eclipse, IntelliJ IDEA和STS等。我们在此推荐使用IntelliJ IDEA,对于日常开发,其社区版的功能已经足够了。在安装完IntelliJ IDEA后,您可以根据初始化设置教程对IntelliJ IDEA进行配置,随后可通过阅读必备快捷键了解常用的快捷键。

Java Chassis和Saga项目使用了Google Code Style作为代码风格,配置文件可以在本项目 etc 目录下找到。其中,目录中也有Eclipse的代码风格,读者可以直接导入使用。

![code style files]({{ site.url }}{{ site.baseurl }}/assets/images/intellij.code.style.3.png){: .align-center}

{% include toc %}

IntelliJ IDEA 配置

IntelliJ IDEA的配置方法如下

  1. 打开IntelliJ配置 ![IntelliJ Settings]({{ site.url }}{{ site.baseurl }}/assets/images/intellij.code.style.4.png){: .align-center}

  2. Import 配置文件 etc/intellij-java-google-style.xml ![import code style]({{ site.url }}{{ site.baseurl }}/assets/images/intellij.code.style.1.png){: .align-center}

  3. 打开已修改而未提交的文件,并打开格式化文件对话框 ![reformat file dialog]({{ site.url }}{{ site.baseurl }}/assets/images/intellij.code.style.5.png){: .align-center}

  4. 选择只格式化修改部分 ![reformat options]({{ site.url }}{{ site.baseurl }}/assets/images/intellij.code.style.2.png){: .align-center}

配置完成后,后续按快捷键 (Ctrl+Alt+i) 格式化修改文件即可。更多关于IntelliJ的使用技巧可阅读IntelliJ教程

下一步