Storing web content in a JAR file

后端 未结 6 1685
被撕碎了的回忆
被撕碎了的回忆 2021-02-14 03:16

Is it possible to store web content (such as JSPs, HTML, images, CSS etc) in a JAR file?

I\'ve been looking at various options at modularising our web applications and t

6条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-14 03:26

    Yes, it is possible to store files e.g. properties, xml, xslt, image etc; in a JAR (or WAR) file and pull them at runtime.

    To load a resource from your deployment jar, use the following code.

    this.getClass().getClassLoader().getResourceAsStream( filename ) ;
    

    In a maven project, folders & files placed in resources are included in the jar. The filename is relative to the root of jar file, so "./filename.xml" would match the file filename.xml placed in "/src/java/resources".

提交回复
热议问题