Accessing resources outside the project path via soft connect under Linux

Source: Internet
Author: User

in the development of Javaweb project, picture uploading is a more common scene. This is usually done by building a folder under the project path and uploading it to the folder so that the image can be accessed directly as a static resource. The advantage of this is that access to the image is particularly convenient; The disadvantage is that you should manually back up the pictures when you redeploy, or the picture will be lost.

today, through the online access to some information, the following 2 options were found:
(1) Configuring the Tomcat virtual directory
        • The benefit of this scenario is that files in the virtual directory can also be accessed like static resources
        • in the ointment is uploading images also need to upload to the absolute path of the virtual directory, on the Internet do not see how to get the absolute path of the virtual directory method; The solution that comes to mind is to configure a properties file with an absolute path.
more relevant content can be found on the Internet. Reference: http://blog.csdn.net/l1028386804/article/details/52389722
(2) through the Linux soft connection implementation
        • The benefit of this scheme is that it can be accessed just like a static file, and uploads are uploaded directly to the folder under the project root directory. The kind of program that is said at the beginning of the article is the same as the code.
        • The disadvantage is that you need to use the Linux command to the above project root directory of the upload folder to do a soft connection, the uploaded file after the connection is actually uploaded to the soft-connected folder.
        • Another problem is the need to configure Tomcat to support soft connections
combined with the above 2 cases, I choose to adopt a soft connection, the following talk about the Linux soft connection。
One, soft connection introduction Soft connection command:
 
   
  
  1. ln -s 源文件 目标文件
Specific introduction can be referred to: http://www.cnblogs.com/crazylqy/p/5821105.html second, the actual case (1) in the code, we upload the file toProject Path (Webroot or WebApp)of the next images/folder; How this upload is implemented, not introduced. (2) Processing in Linux
      • Create a folder named Images in Linux. ( This folder name should be the same name as the folder you are going to soft-connect, the location of this folder can be anywhere, but not generally outside of Tomcat.) )
      • Go to the deployed project path under Tomcat and create a soft connection. The source folder is the folder created above, and the destination folder is the folder we uploaded later.
         after the successful establishment, you can see the images folder has an arrow, with a graphical interface is actually a shortcut.
 
      • After you establish a soft connection, you can test the upload file, and you will find that the file is uploaded to a folder outside of Tomcat. But the way to access static files is still not accessible, will be reported 404. The reason is that Tomcat does not support soft connections by default and needs to be turned on in Conf/context.xml. The configuration method is as follows:

version tomcat5, 6, 7:

 <Contextallowlinking= "true" />

Tomcat8, version 9:

            <Context><Resourcesallowlinking= "true" /></Context>

More Configuration reference: http://www.cnblogs.com/wuxun1997/p/6769971.html

      • Once the configuration is complete, you are done.

For more examples of soft connections, refer to:http://blog.csdn.net/ggmmqq/article/details/8253570

Http://www.cnblogs.com/wuxun1997/p/6769971.html


Three, soft connection considerations

(1) The removal of soft connections requires special attention, specific reference

Http://www.cnblogs.com/cartsp/p/6437046.html

http://blog.csdn.net/zhenwenxian/article/details/16369767

(2) I found that the re-deployment of eclipse will still be the source directory of soft links to delete files, this is a very strange place. But OPS is definitely not using eclipse for redeployment. So don't worry.

(3) after redeploying the project, the soft connection needs to be re-established


There is a follow-up article on the Linux Soft link, recommended reading.











Accessing resources outside the project path via soft connect under Linux

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.