目录

  1. Java 环境配置
    1. 下载 JDK
    2. 服务器配置
  2. gradle 配置
    1. 下载 gradle
    2. 配置
    3. 配置下载加速

Java 环境配置

Java 的环境配置主要分为两步:下载 Java 开发环境(JDK)以及配置 JAVA_HOME 环境变量

下载 JDK

由于现在下载 JDK 需要验证,所以只能先下载到本地,然后上传到服务器

前往Oracle 官网,下载 JDK8,根据自己的系统位数,选择相应的版本下载

系统位数下载版本
32 位jdk-8u45-linux-i586.tar.gz
64 位jdk-8u45-linux-x64.tar.gz

服务器配置

将 JDK 上传到服务器之后,距离使用 Java 还有以下几步(以JDK8为例)

1
2
3
4
5
6
7
8
9
10
11
12
# 创建 jdk 目录
mkdir -p /usr/java
# 解压安装包
tar zxvf jdk-8u45-linux-x64.tar.gz
# 增加到环境变量中
vim /etc/profile
-----------------
export JAVA_HOME=/usr/java/jdk1.8.0_291
export PATH=${JAVA_HOME}/bin:$PATH
-----------------
# 测试
java -version

gradle 配置

gradle 是部分 Java 项目构建工作,因此本文介绍 Gradle 如何下载并配置

下载 gradle

📖前往gradle 官网下载到本地,并解压

配置

需要配置三个参数GRADLE_HOMEpathGRADLE_USER_HOME

参数含义
GRADLE_HOMEgradle 的基本路径
path命令执行时查找路径
GRADLE_USER_HOMEgradle 仓库

配置下载加速

✨Gradle 还是从 maven 仓库下载的,给 gradle 安装目录下 init.d 文件夹,放一个 init.gradle 文件即可完成加速

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
gradle.projectsLoaded {
rootProject.allprojects {
buildscript {
repositories {
def JCENTER_URL = 'https://maven.aliyun.com/repository/jcenter'
def GOOGLE_URL = 'https://maven.aliyun.com/repository/google'
def NEXUS_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
all { ArtifactRepository repo ->
if (repo instanceof MavenArtifactRepository) {
def url = repo.url.toString()
if (url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $JCENTER_URL."
println("buildscript ${repo.url} replaced by $JCENTER_URL.")
remove repo
}
else if (url.startsWith('https://dl.google.com/dl/android/maven2/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $GOOGLE_URL."
println("buildscript ${repo.url} replaced by $GOOGLE_URL.")
remove repo
}
else if (url.startsWith('https://repo1.maven.org/maven2')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
println("buildscript ${repo.url} replaced by $REPOSITORY_URL.")
remove repo
}
}
}
jcenter {
url JCENTER_URL
}
google {
url GOOGLE_URL
}
maven {
url NEXUS_URL
}
}
}
repositories {
def JCENTER_URL = 'https://maven.aliyun.com/repository/jcenter'
def GOOGLE_URL = 'https://maven.aliyun.com/repository/google'
def NEXUS_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
all { ArtifactRepository repo ->
if (repo instanceof MavenArtifactRepository) {
def url = repo.url.toString()
if (url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $JCENTER_URL."
println("buildscript ${repo.url} replaced by $JCENTER_URL.")
remove repo
}
else if (url.startsWith('https://dl.google.com/dl/android/maven2/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $GOOGLE_URL."
println("buildscript ${repo.url} replaced by $GOOGLE_URL.")
remove repo
}
else if (url.startsWith('https://repo1.maven.org/maven2')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
println("buildscript ${repo.url} replaced by $REPOSITORY_URL.")
remove repo
}
}
}
jcenter {
url JCENTER_URL
}
google {
url GOOGLE_URL
}
maven {
url NEXUS_URL
}
}
}
}