HiSEN

Linux-Ubuntu安装:JDK & Tomcat & Maven - 简单教程

在网速搜索很多教程,感觉写的都太难了我去

准备工作:

  1. 下载JDK,并解压(选择适合自己的版本:地址)
  2. 下载Tomcat,并解压(选择适合自己的版本:地址)
  3. 下载Maven,并解压(选择适合自己的版本:地址)

目录约定:

  1. java路径:/usr/hisen/soft/java/jdk8
  2. tomcat路径:/usr/hisen/soft/tomcat/tomcat8
  3. maven路径:/usr/hisen/soft/maven/maven-3.5.0

说明以上路径都是解压之后的,请解压之后自行重命名文件夹等工作

下面开始配置环境变量:

1
sudo vi /etc/profile

底部添加:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#java的环境变量配置
export JAVA_HOME=/usr/hisen/soft/java/jdk8
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib:$JRE_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin

#tomcat的环境变量配置
export CATALINA_HOME=/usr/hisen/soft/tomcat/tomcat8
export CLASSPATH=.:$JAVA_HOME/lib:$CATALINA_HOME/lib
export PATH=$PATH:$CATALINA_HOME/bin

#maven环境变量
export MAVEN_HOME=/usr/hisen/soft/maven/maven-3.5.0
export MAVEN_OPTS="-Xms256m -Xmx512m"
export PATH=${MAVEN_HOME}/bin:$PATH

让刚刚的配置生效:

1
source /etc/profile

查看maven

1
mvn -v

查看java版本

1
java -version

如果还是默认的OpenJDK

1
2
3
4
5
sudo update-alternatives --install /usr/bin/java java /usr/hisen/soft/java/jdk8/bin/java 300  
sudo update-alternatives --install /usr/bin/javac javac /usr/hisen/soft/java/jdk8/bin/javac 300

#选择默认JDK即可
sudo update-alternatives --config java

进入tomcat的bin目录

1
sudo vi catalina.sh

顶部添加

1
2
3
#让tomcat知道java在哪里
JAVA_HOME=/usr/hisen/soft/java/jdk8
JRE_HOME=$JAVA_HOME/jre

之后进入在tomcat bin目录执行

1
2
3
4
5
6
7
hisen@hisen:/usr/hisen/soft/tomcat/tomcat8/bin$ sudo sh startup.sh
Using CATALINA_BASE: /usr/hisen/soft/tomcat/tomcat8
Using CATALINA_HOME: /usr/hisen/soft/tomcat/tomcat8
Using CATALINA_TMPDIR: /usr/hisen/soft/tomcat/tomcat8/temp
Using JRE_HOME: /usr/hisen/soft/java/jdk8/jre
Using CLASSPATH: /usr/hisen/soft/tomcat/tomcat8/bin/bootstrap.jar:/usr/hisen/soft/tomcat/tomcat8/bin/tomcat-juli.jar
Tomcat started.

这样就启动了tomcat!!!!

注意

如果没有在 catalina.sh 添加java路径,会报错

1
2
3
hisen@hisen-VirtualBox:/usr/hisen/soft/tomcat/tomcat8/bin$ sudo sh startup.sh
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program