如何在CentOS 7上配置Java的Maven开发环境

直接下载JDK历史版本https://www.oracle.com/technetwork/java/javase/downloads/index.html

查看CentOS自带JDK是否已安装。
输入:yum list installed |grep java

若有自带安装的JDK,如何卸载CentOS系统自带Java环境?
卸载JDK相关文件输入:yum -y remove java-1.8.0-openjdk*
卸载tzdata-java输入:yum -y remove tzdata-java.noarch

使用yum安装Java环境。

输入:yum -y install java-1.8.0-openjdk*

[root@contoso13 ~]# find / -name java  -xtype f
/etc/alternatives/java
/var/lib/alternatives/java
/usr/bin/java
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-8.b10.el7_5.x86_64/jre/bin/java
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-8.b10.el7_5.x86_64/bin/java
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-8.b10.el7_5.x86_64-debug/jre/bin/java
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-8.b10.el7_5.x86_64-debug/bin/java
[root@contoso13 ~]# java -version
openjdk version "1.8.0_171"
OpenJDK Runtime Environment (build 1.8.0_171-b10)
OpenJDK 64-Bit Server VM (build 25.171-b10, mixed mode)
[root@contoso13 ~]#
 

安装Maven

http://maven.apache.org/install.html

[root@contoso13 ~]# cd /opt && wget http://mirror.reverse.net/pub/apache/maven/maven-3/3.5.3/binaries/apache-maven-3.5.3-bin.tar.gz

[root@contoso13 opt]# tar xzvf apache-maven-3.5.3-bin.tar.gz

[root@contoso13 ~]# cat >> /etc/profile
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-8.b10.el7_5.x86_64
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH
export PATH=/opt/apache-maven-3.5.3/bin:$PATH
export MAVEN_HOME=/opt/apache-maven-3.5.3

[root@contoso13 ~]# source /etc/profile
[root@contoso13 ~]# cat /etc/profile

[root@contoso13 ~]# mvn -v
Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-25T03:49:05+08:00)
Maven home: /opt/apache-maven-3.5.3
Java version: 1.8.0_171, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-8.b10.el7_5.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-862.el7.x86_64", arch: "amd64", family: "unix"
[root@contoso13 ~]#

下载Eclipse开发工具

[root@contoso13 ~]# cd /opt && wget http://mirror.csclub.uwaterloo.ca/eclipse/technology/epp/downloads/release/oxygen/3a/eclipse-java-oxygen-3a-linux-gtk-x86_64.tar.gz

配置settings.xml文件

[root@contoso13 ~]# cat > /opt/apache-maven-3.5.3/conf/settings.xml

<?xml version="1.0" encoding="UTF-8"?>

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

  <localRepository>${user.home}/.m3/repository</localRepository>
  <interactiveMode>true</interactiveMode>
  <usePluginRegistry>false</usePluginRegistry>
  <offline>false</offline>
  <mirrors>
     <mirror>
      <id>alimaven</id>
      <mirrorOf>central</mirrorOf>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    </mirror>
  </mirrors>
</settings>
[root@contoso13 ~]# cat /opt/apache-maven-3.5.3/conf/settings.xml > /root/.m3/repository/settings.xml

勾选         Create a simple project(skip archetype selection)
不勾选      Use default Workspace location
Location:  /opt/sources

Group Id:      com.contoso
Artifact Id:   spring-boot-jwt
Version:       0.0.1-SNAPSHOT
Packaging:     war

Parent
Group Id:      org.springframework.boot
Artifact Id:   spring-boot-starter-parent
Version:       1.5.9.RELEASE
Relative Path:

 

配置 Tomcat (开发工具运行时有嵌入Tomcat,故这是可选配置,war/jar包发布到独立的Tomcat服务器上运行,必须配置Tomcat)

https://tomcat.apache.org/download-90.cgi

cd /usr/local && wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-9/v9.0.10/bin/apache-tomcat-9.0.10.tar.gz
tar zxvf apache-tomcat-9.0.10.tar.gz

find / -name catalina.sh

/usr/local/apache-tomcat-9.0.10/bin/catalina.sh   //find命令输出的结果

 

cat > /usr/local/apache-tomcat-9.0.10/conf/tomcat-users.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<tomcat-users xmlns="http://tomcat.apache.org/xml"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
              version="1.0">
<!--
  NOTE:  By default, no user is included in the "manager-gui" role required
  to operate the "/manager/html" web application.  If you wish to use this app,
  you must define such a user - the username and password are arbitrary. It is
  strongly recommended that you do NOT use one of the users in the commented out
  section below since they are intended for use with the examples web
  application.
-->
<!--
  NOTE:  The sample user and role entries below are intended for use with the
  examples web application. They are wrapped in a comment and thus are ignored
  when reading this file. If you wish to configure these users for use with the
  examples web application, do not forget to remove the <!.. ..> that surrounds
  them. You will also need to set the passwords to something appropriate.
-->
<!--
  <role rolename="tomcat"/>
  <role rolename="role1"/>
  <user username="tomcat" password="<must-be-changed>" roles="tomcat"/>
  <user username="both" password="<must-be-changed>" roles="tomcat,role1"/>
  <user username="role1" password="<must-be-changed>" roles="role1"/>
-->
        <role rolename="manager-gui"/>
        <role rolename="admin-gui"/>
        <user username="tomcat" password="s3cret" roles="manager-gui,admin-gui"/>
</tomcat-users>

 

cat > /usr/local/apache-tomcat-9.0.10/conf/context.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!-- The contents of this file will be loaded for each web application -->
<Context>

    <!-- Default set of monitored resources. If one of these changes, the    -->
    <!-- web application will be reloaded.                                   -->
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
    <WatchedResource>WEB-INF/tomcat-web.xml</WatchedResource>
    <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>

    <!-- Uncomment this to disable session persistence across Tomcat restarts -->
    <Manager pathname="" />
</Context>

 

cat > /usr/local/apache-tomcat-9.0.10/webapps/manager/META-INF/context.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<Context antiResourceLocking="false" privileged="true" >
  <!--
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
  -->
  <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
 

</Context>

 

/usr/local/apache-tomcat-9.0.10/bin/startup.sh        //启动Tomcat

/usr/local/apache-tomcat-9.0.10/bin/shutdown.sh     //关闭Tomcat

 

# /usr/local/apache-tomcat-9.0.10/bin/startup.sh
Using CATALINA_BASE:   /usr/local/apache-tomcat-9.0.10
Using CATALINA_HOME:   /usr/local/apache-tomcat-9.0.10
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-9.0.10/temp
Using JRE_HOME:        /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-8.b10.el7_5.x86_64
Using CLASSPATH:       /usr/local/apache-tomcat-9.0.10/bin/bootstrap.jar:/usr/local/apache-tomcat-9.0.10/bin/tomcat-juli.jar

Tomcat started.

 

# /usr/local/apache-tomcat-9.0.10/bin/shutdown.sh
Using CATALINA_BASE:   /usr/local/apache-tomcat-9.0.10
Using CATALINA_HOME:   /usr/local/apache-tomcat-9.0.10
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-9.0.10/temp
Using JRE_HOME:        /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-8.b10.el7_5.x86_64
Using CLASSPATH:       /usr/local/apache-tomcat-9.0.10/bin/bootstrap.jar:/usr/local/apache-tomcat-9.0.10/bin/tomcat-juli.jar

 

Spring Boot官网上推荐的开发工具是 Spring Tools Suite 简称STS,这款工具集成了Spring Cloud插件,后面有关Spring Cloud的文章我都会使用此款开发工具开发

http://spring.io/tools/sts/all/

wget http://download.springsource.com/release/STS/3.9.5.RELEASE/dist/e4.8/spring-tool-suite-3.9.5.RELEASE-e4.8.0-linux-gtk-x86_64.tar.gz
cd /opt && tar zxvf spring-tool-suite-3.9.5.RELEASE-e4.8.0-linux-gtk-x86_64.tar.gz

mkdir -p  /root/.m3/repository

cat /opt/apache-maven-3.5.3/conf/settings.xml > /root/.m3/repository/settings.xml

[root@contoso ~]# cat /opt/apache-maven-3.5.3/conf/settings.xml
<?xml version="1.0" encoding="UTF-8"?>

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

  <localRepository>${user.home}/.m3/repository</localRepository>
  <interactiveMode>true</interactiveMode>
  <usePluginRegistry>false</usePluginRegistry>
  <offline>false</offline>
  <mirrors>
     <mirror>
      <id>alimaven</id>
      <mirrorOf>central</mirrorOf>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    </mirror>
  </mirrors>
</settings>
[root@contoso ~]#

安装Docker

官网地址:https://docs.docker.com/install/linux/docker-ce/centos/

$ sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2
$ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

Install Docker CE

$ sudo yum install docker-ce
$ sudo systemctl enable docker  && sudo systemctl start docker
$ sudo usermod -aG docker myth        //其中myth是我的CentOS7.5系统登录用户名称

Install Docker Compose

https://docs.docker.com/compose/install/

sudo curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

Install Docker Machine

$  curl -L https://github.com/docker/machine/releases/download/v0.15.0/docker-machine-$(uname -s)-$(uname -m) >/tmp/docker-machine &&
    chmod +x /tmp/docker-machine &&
    sudo cp /tmp/docker-machine /usr/local/bin/docker-machine
$ sudo tee /etc/yum.repos.d/virtualbox.repo <<-'EOF'
[virtualbox]
name=Oracle Linux/RHEL/CentOS-$releasever/$basearch-VirtualBox
baseurl=http://download.virtualbox.org/virtualbox/rpm/el/$releasever/$basearch
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://www.virtualbox.org/download/oracle_vbox.asc
EOF
cat >> /etc/profile
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/root/.docker/machine/machines/default"
export DOCKER_MACHINE_NAME="default"

 

$ sudo yum -y install VirtualBox-5.2

$ systemctl enable  vboxdrv.service
$ systemctl restart vboxdrv.service

$ virtualbox

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值