项目A 需要访问项目B 的文件, 可以通过 ln-s 命令 将 A 路径链接到项目B 的路径下。
例如:ln -s /data/project/static-resources/admin/resources ./
当前目录下多了一个文件夹,说明连接成功
软连接创建好,我们怎么删除它呢
正确的删除方式(删除软链接,但不删除实际数据)
rm -rf ./resources
错误的删除方式
rm -rf ./resources/ (这样就会把原来resources下的内容删除)
[root@insurance insurance-mall]# service tomcat8 start^C
[root@insurance insurance-mall]# ll
total 60
drwxr-xr-x 3 root root 4096 Jul 16 16:51 css
-rw-r--r-- 1 root root 11799 Aug 23 16:35 detail.html
drwxr-xr-x 2 root root 4096 Jul 16 16:51 fonts
-rw-r--r-- 1 root root 8922 Aug 22 18:08 form.html
drwxr-xr-x 2 root root 4096 Jul 16 16:51 images
-rw-r--r-- 1 root root 1758 Jun 14 13:42 index.html
-rw-r--r-- 1 root root 57 May 9 13:45 index.jsp
drwxr-xr-x 3 root root 4096 Jul 16 16:51 js
-rw-r--r-- 1 root root 2400 Jun 27 16:51 payment.html
-rw-r--r-- 1 root root 2150 Jul 24 16:33 pay-result.html
lrwxrwxrwx 1 root root 38 Aug 24 16:00 resources -> /data/project/insurance-web/resources/
drwxr-xr-x 3 root root 4096 Aug 22 11:47 WEB-INF
[root@insurance insurance-mall]#
连接过来之后, 还需要对tomcat 的 context 进行设置 允许连接访问, 这里踩了一个坑
发现allowLinking 没有生效。
查资料发现,这是 tomcat7 的设置方式, 而我使用的是tomcat8, 正确配置如下
加入 <Resources allowLinking="true"></Resources>
<Context>
<Resources allowLinking="true"></Resources>
<!-- Default set of monitored resources. If one of these changes, the -->
<!-- web application will be reloaded. -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->
</Context>