> For the complete documentation index, see [llms.txt](https://jun-wang.gitbook.io/learnjava/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jun-wang.gitbook.io/learnjava/ji-shu-xue-xi/web-zhong-jian-jian-xue-xi/resin-xue-xi.md).

# Resin学习

## 1. resin简介

刚入职的公司用的后台服务器是resin，故因此学习记录一下。

resin是一个非常流行的web引用服务器，对servlet和jsp提供了良好的支持，自身采用java开发。resin分为普通版和专业版，主要区别是专业版支持缓存和负载均衡。

## 2. 安装配置

官方下载地址：<http://caucho.com/products/resin/download#download。由于是在windows上运行，笔者下载的是zip版本的，直接解压，运行根目录下的resin.exe（如果闪退就右键使用管理员方式运行）就可以启动了，提供了界面来进行启停操作。启动成功后访问http://localhost:8080/，就会出现resin的主页，显示**Resin®> Default Home Page\*\*，和tomcat一样，将项目文件或者war包丢进webapps下面就可以访问了。resin的配置文件在conf文件夹下，在resin.xml中可以发布自己的工程，比如：

```markup
<!-- the default host, matching any host name -->
<host id="" root-directory=".">
    <!--
         - webapps can be overridden/extended in the resin.xml
        -->
    <web-app id="/" root-directory="webapps/ROOT"/>
    <!-- 发布自己的工程：learnSpringMVC，相当于tomcat的context配置 -->
    <web-app id="/test" root-directory="webapps/learnSpringMVC"/>

</host>
```

然后就可以通过访：<http://localhost:8080/test/，访问自己的项目了。在本项目中，实际访问的是learnSpringMVC下面的index.jsp。在webapp下发布了自己的工程，就可以通过自己的自定义头路径访问发布的接口了，比如之前没有配置web-app时，访问接口：http://localhost:8080/learnSpringMVC/hello/showdemo，配置完后应该访问：http://localhost:8080/test/hello/showdemo。learnSpringMVC项目地址：https://github.com/WangJun-SCU/LearnSpringMVC>

```markup
<!-- 这样可以配置访问端口，如下配置了端口是8089，再访问页面就需要换成8089而不是8080了 -->
<server-default>
    <http address="*" port="8089" />
</server-default>

<!-- the default host, matching any host name -->
<host id="" root-directory=".">
    <!--
         - webapps can be overridden/extended in the resin.xml
        -->
    <web-app id="/" root-directory="webapps/ROOT"/>
    <!-- 发布自己的工程：learnSpringMVC，相当于tomcat的context配置 -->
    <web-app id="/test" root-directory="webapps/learnSpringMVC"/>

</host>
```

**Linux下启停**

```
# 启动
sh resin.sh start
# 停止
sh resin.sh stop
```

## 3. resin和tomcat的比较

之前接触到的项目都是使用Tomcat作为服务器，到底resin和tomcat的区别是什么呢？为什么现在的项目使用resin，通过查询资料总结整理一下。

1. **生态：**&#x9996;先tomcat作为javaweb的首选服务器，用户数量肯定比resin多，并且相关的文档也比较丰富和完善了。
2. **和eclipse集成：**&#x72;esin和eclipse集成比较复杂，并且调试开发也复杂，更新类后会自动重启。
3. **热部署：**&#x5728;更新class及jsp或者配置文件（比如web.xml）时，resin会自动部署重启，但是在开发环境下如果配置了session超时会比较麻烦。而tomcat可以按需配置修改java和jsp文件时是否重启，但是在生产环境下更新配置文件必须手动重启，如果一次性更新太多文件时，经常造成tomcat重启失败。
4. **速度：**&#x72;esin的速度相对于tomcat来说快很多。
5. **报错机制：**&#x72;esin的报错机制更加人性化，tomcat报错不明显对于新手来说比较困难。
6. **中文支持：**&#x72;esin比tomcat具有更好的中文支持。

> 参考：
>
> <https://blog.csdn.net/xiongyouqiang/article/details/78944825>
>
> <https://blog.csdn.net/shehun1/article/details/38185219>
