zoukankan      html  css  js  c++  java
  • 安装java项目开发环境


    搭建java

     

    查看本机是否已有java

    如果有,请卸载。

    下载jdk

    复制到服务器中

    临时配置
    你在shell里面改,只是做了临时更改啊,一重启就没了

     配置到系统的环境变量里

    export JAVA_HOME=/usr/local/java/jdk-9.0.1
    export PATH=${PATH}:${JAVA_HOME}/bin
    source /etc/profile
    echo ${JAVA_HOME}
    echo ${PATH}

    永久配置java环境
    打开sh文件
    在结尾添加这么几行

    export JAVA_HOME=/usr/local/jdk-9.0.1
    export PATH=${PATH}:${JAVA_HOME}/bin

    立即生效配置

    source /etc/profile



    加测安装成功否
    注意:可能会提示没权限,若提示,则执行

    chmod 777 /usr/local/jdk-9.0.1/bin/java
    chmod 777 /usr/local/jdk-9.0.1/bin/javac
    //777代表,user,group ,others ,都有读写和可执行权限。

    一键安装

     上边的步骤可能麻烦,所以我写了个一键安装的脚本

    curl -O https://dshvv.oss-cn-beijing.aliyuncs.com/ijava.sh && chmod 755 ./ijava.sh && ./ijava.sh  && rm -rf ./ijava.sh

    下边是脚本的内容,如果感兴趣可以看看

    echo -e "33[31m------------------------------下载jdk---------------------33[0m";
    yum install wget -y
    cd /home
    wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u141-b15/336fa29ff2bb4ef291e347e091f7f4a7/jdk-8u141-linux-x64.tar.gz"
    echo -e "33[31m------------------------------解压jdk---------------------33[0m";
    tar -zxvf /home/jdk-8u141-linux-x64.tar.gz
    echo -e "33[31m------------------------------配置环境变量---------------------33[0m";
    sed -i '$aexport JAVA_HOME=/home/jdk1.8.0_141
    export PATH=${PATH}:${JAVA_HOME}/bin' /etc/profile
    source /etc/profile
    echo -e "33[1;32m------------------------------java已经安装完成---------------------
    可能需要重启shell方可生效
    用java -version来验证33[0m"
    View Code



     搭建Tomcat

    下载tomcat

     下载解压到指定目录

     然后运行

    ./startup.sh

    可能会包没有权限的错
    给权限就好了

    chmod 777 ./catalina.sh
    //启动startup.sh,调试模式catalina.sh

     

    测试

    写一个简单的javaWeb项目如下
    TestServlet

    package com.dsh;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.HashMap;
    import java.util.Map;
    
    public class TestServlet extends HttpServlet {
        public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
            //生成HTTP响应结果
            PrintWriter out = res.getWriter();
            res.setContentType("application/json; charset=utf-8");
            String jsonStr = "{"status":"true","data":"hello,this is test Api!"}";
            out.print(jsonStr);
            out.close();
        }
    }

    index.jsp

    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <%
      String path = request.getContextPath();
      String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    <html>
      <head>
        <title>测试</title>
      </head>
      <body>
          <p> Hello,world!</p>
          <button>测试servlet接口</button>
          <div>请看console</div>
          <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
          <script>
            $('button').click(function () {
                var url='<%=basePath%>test';
                $.get(url).then(function (rep) {
                    console.log(rep)
                })
            })
          </script>
      </body>
    </html>

    目录结构

    然后将outartifactsTest_war_exploded复制到服务器  tomcat>webapp下就行了

    然后访问测试
    http://47.93.52.112:8080/Test/

  • 相关阅读:
    HDU1029 Ignatius and the Princess IV
    UVA11039 Building designing【排序】
    UVA11039 Building designing【排序】
    POJ3278 HDU2717 Catch That Cow
    POJ3278 HDU2717 Catch That Cow
    POJ1338 Ugly Numbers(解法二)
    POJ1338 Ugly Numbers(解法二)
    UVA532 Dungeon Master
    UVA532 Dungeon Master
    POJ1915 Knight Moves
  • 原文地址:https://www.cnblogs.com/dshvv/p/7819015.html
Copyright © 2011-2022 走看看