As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center作为指导。
                            
                        
                    
                
                                6年前关闭。
            
                    
有时我们必须在项目中保留很多小文件(例如isomorphic的智能客户端)。大约有1万个小文件。 svn(我不知道git如何处理),复制,打包等问题,但是这些文件几乎永远不会改变,因为它只是一个外部库。有什么办法可以将它们保存在单个zip文件中,并告诉tomcat从该文件内部托管它们?还是应该不同地对待它们?有最佳做法吗?

更准确地说。那是我的文件夹结构:

src/main/
     +---webapp/
     |      +---static/    <-- thousand 3rd party's files in this dir
     |
     +---java/


Maven将与我的代码和静态文件建立战争,它将起作用。但是在战争爆发之前,它是一个可以处理这么多文件的PINA。我想……

src/main/
     +---webapp/
     |      +---static.zip    <-- only 1 file
     |
     +---java/


在流行的Web服务器上可以吗?

最佳答案

如果您在Servlet-3.0 Web应用程序中,请创建一个jar文件,并将所有静态资源放在此jar文件中的META-INF / resources下。然后将此jar文件放在Web应用程序的WEB-INF / lib中,容器将为您的静态资源提供服务,就像它们位于Webapp的根目录一样。

因此,如果您希望将静态资源foo.hml的URL作为

http://localhost/myWebApp/static/foo.html,


您应该具有以下目录/ jar结构:

webapp
  WEB-INF
    lib
      static.jar
        META-INF
          resources
            static
              foo.html

10-07 19:04
查看更多