java开发环境构建

一. 基本工具安装

1. 配置终端命令别名

vim ~/.bash_profile
***********************************************
# for color
export CLICOLOR=1
 
alias l='ls -CF'
alias ll='ls -l'
alias la='ls -al'
***********************************************
source ~/.bash_profile

2. 配置git

    (1) 添加git的配置文件

vim ~/.gitconfig
***********************************************
[user]
name = "自己的中文名字"
email = "公司邮箱"
[color]
ui = auto
branch = auto
diff = auto
status = auto
[color "branch"]
current = green
local = yellow
remote = red
[color "diff"]
meta = yellow bold
frag = magenta bold
old = red bold
new = green bold
[color "status"]
added = yellow
changed = green
untracked = cyan
[alias]
st = status
di = diff
ci = commit
co = checkout
br = branch
***********************************************

    (2) 生成并添加ssh密钥,使用以下命令

ssh-keygen -t rsa -C "邮箱"

    (3) 确认已开通GitLab账号及权限。登录http://code.qijiayoudao.net/,在左侧 profile settings中,点击 SSH Keys,上传自己的ssh-key,即~/.ssh/id_rsa.pub中的内容

3. 安装JDK

    (1) 从百度云盘地址http://pan.baidu.com/s/1skvJAcH下载JDK安装文件jdk-7u76-macosx-x64.dmg (下载时间比较长,也可以从其他同事那通过QQ传输)

    (2) 双击dmg文件进行安装

    (3) 修改.bash_profile配置文件

vim ~/.bash_profile
***********************************************
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=$PATH:$JAVA_HOME
***********************************************
source ~/.bash_profile

    (4) 验证

java -version

4. 安装MAVEN

    (1) 从百度云盘地址http://pan.baidu.com/s/1hrwHPgo下载MAVEN安装文件apache-maven-3.0.3-bin.tar

    (2) 安装:双击tar文件解压,移动apache-maven-3.0.3目录到自己设定的MAVEN目录下,建议/Users/yourName/Programs

    (3) 修改.bash_profile配置文件

vim ~/.bash_profile
***********************************************
export MAVEN_HOME=/Users/yourName/Programs/apache-maven-3.0.3
export PATH=$PATH:$JAVA_HOME:$MAVEN_HOME/bin
export MAVEN_OPTS='-Xmn400m -Xms1024m -Xmx1024m -Xss1m -XX:PermSize=384m -XX:MaxPermSize=384m'
***********************************************
source ~/.bash_profile

    (4) 添加settings.xml配置文件

mkdir ~/.m2
vim ~/.m2/settings.xml
***********************************************
<settings>
<!-- 配置maven本地repository的位置,可选 -->
<localRepository>/Users/wangbo/.m2/repository</localRepository>
<!-- 配置开发者打包jar并上传nexus的用户名和密码 -->
<servers>
        <server>
                <id>nexus-releases</id>
                <username>admin</username>
                <password>G0g1@$qw</password>
        </server>
        <server>
                <id>nexus-snapshots</id>
                <username>admin</username>
                <password>G0g1@$qw</password>
        </server>
</servers>
<profiles>
<!-- 配置maven私服的地址,maven在构建时会先从私服尝试下载,如找不到再从中央仓库下载 -->
<profile>
       <id>nexus</id>
       <repositories>
               <repository>
                       <id>nexus</id>
                       <name>local private nexus</name>
                       <url>http://123.57.204.47:8081/nexus/content/groups/public</url>
               </repository>
       </repositories>
       <pluginRepositories>
               <pluginRepository>
                       <id>local-plugin-repository</id>
                       <name>local private plugin repository</name>
                       <url>http://123.57.204.47:8081/nexus/content/groups/public</url>
                       <releases>
                               <enabled>true</enabled>
                       </releases>
                       <snapshots>
                               <enabled>false</enabled>
                       </snapshots>
               </pluginRepository>
       </pluginRepositories>
</profile>
</profiles>
<activeProfiles>
       <activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
***********************************************

    (5) 验证

mvn -version

5. 安装homebrew

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew -v

6. 安装thrift

brew install thrift

二. 安装mysql本地测试库

1. 安装本地mysql

brew install mysql
mysql.server start

2. 创建saas用户

mysql -uroot
> CREATE USER 'user'@'localhost' IDENTIFIED BY '123123';
> GRANT ALL ON *.* TO 'user'@'localhost';
> exit

3. 从线下测试库(dev-01)将business和management两个库dump出sql文件business_日期.sql和management_日期.sql,导入到本地库

mysql -usaas -p
> create database business;
> source business_日期.sql;
> create database management;
> source management_日期.sql;

三. 拷贝代码到本地,运行

1. 从代码仓库获取backend代码,建议放在~/Workspace/目录下

git clone git@123.45.678.90:xxxx/backend.git

2. 从命令行运行工程

mvn clean jetty:run

3. 验证,访问http://localhost:8080/index

四. 安装开发环境IDEA

1. 从百度云盘地址http://pan.baidu.com/s/1i4nSynb下载IDEA安装文件ideaIU-14.0.3.dmg

2. 双击dmg文件进行安装

3. 运行IDEA,会提示"需要安装旧Java se 6运行环境才能打开",点击"更多信息",打开JDK6的下载也,下载安装,再次运行IDEA

    注:此时JDK7和JDK6同时存在。想要看已经安装的JDK版本及目录,运行命令"/usr/libexec/java_home -V";想要看默认JDK的路径,运行命令"/usr/libexec/java_home",截图如下:

4. 从网上自行下载相应版本的注册码并激活,可以试试这个网页中的注册码:http://hw1287789687.iteye.com/blog/2153894

5. 导入代码

    (1) 点击Import Project,找到要导入工程的pom.xml

   

    (2) 保持默认设置,一路下一步;直到添加JDK路径,点"加号"浏览到JDK1.7的路径并添加,默认是/Library/Java/JavaVirtualMachines/jdk1.7.0_76.jdk/Contents/Home;最后点击Finish

    (3) 导入完成后,可能需要等待一段时间下载依赖的maven等,待工程代码的错误完全解决,点击右上角的"Edit Configurations"添加运行项

    (4) 在左侧点击"加号"并选择Maven,在右侧填写相关的信息及命令如下图

    (5) 点击右上角的Debug按钮,运行工程,此时会弹出未配置Maven目录的提示,点击OK,再从底下的Event Log点击configuration dialog,点击Override并浏览到Maven的安装目录

    (6) 再次点击右上角的Debug按钮,运行工程,如下图所示,运行成功,访问http://localhost:8080/index验证

posted @ 2017-06-04 09:25  jiguojing  阅读(510)  评论(0编辑  收藏  举报