发表于: 2020-07-04 23:00:52

1 1556


今天做了什么:

在jetty,resin服务器部署项目

配置resin的access.log


resin:

直接用Xftp工具把打包好的war上传到resin的webapps目录下的ROOT目录

进入到ROOT命令直接解压war包



使用浏览器输入ip:port/student/1/韦延伦成功返回数据

cotroller代码

@RequestMapping("/student")
@Controller
public class FalseDataController {
@RequestMapping(value = "{id}/{name}", method = RequestMethod.GET)
@ResponseBody
   public Student getJson(@PathVariable Integer id ,@PathVariable String name) {
Student student = new Student();
       student.setName(name);
       student.setId(id);
       return student ;
   }

}

终于发现了昨天用document-directory配置失败的原因了,还真是服务器内存不够的原因!!!今天听师兄的升上2G内存之后直接成功了。

把war包放到任意目录,id是war包的名字,document-directory的路径是war的绝对路径名(但是不要有war后缀), archive-path的路径是加war后缀名。

在浏览器输入url后可以看到war包被自动解压了。

圈中的task2和id的值相对应

jetty:

jetty9有点东西。

我还以为直接扔war包进webapps里面直接启动就行了

想不到还要在web-INF目录下加一个xml文件才能打包上传才能部署成功

<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
   <Set name="contextPath">/task2</Set>
   <Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/task2.war</Set>
</Configure>




resin日志配置:

打开resin目录下的conf目录

vim cluster-default.xml 

找到下面的标签,加%D,后保存

     <access-log path="log/access.log" 

                 format='%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"%D'

                 rollover-period="1W"/>

进入到log目录使用

tail -f access.log 

把access.log里最尾部的内容显示在屏幕上,并且不断刷新,看到最新的文件内容。

执行get请求

183.13.191.192 - "null-user" [04/Jul/2020:22:02:20 +0800] "GET /task2/student/1/%E9%9F%A6%E5%BB%B6%E4%BC%A6 HTTP/1.1" 200 118 "-" "PostmanRuntime/7.26.1"214000

参考官方文档

tomcat日志配置

vim server.xml

 <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"

               prefix="localhost_access_log" suffix=".txt"

               pattern="%h %l %u [%{yyyy-MM-dd HH:mm:ss}t] %{X-Real_IP}i &quot;%r&quot; %s %b %D %F" />

      </Host>



遇到的问题: 

resin部署问题

原因是:web.xml头文件版本太高

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
        xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
        id="WebApp_ID" version="4.0">

解决办法:换到3.0版本

<web-app version="3.0"
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

postman测试成功

明天计划的事情: 

配置jetty的日志

学习shell脚本

收获:

接触新东西要看官方文档少踩坑。



返回列表 返回列表
评论

    分享到