webapp-scrapbook.xtp

来自「RESIN 3.2 最新源码」· XTP 代码 · 共 55 行

XTP
55
字号
<document>  <header>    <product>resin</product>    <title>Web Applications Scrapbook</title>    <description>      <p>A repository of notes and comments that will        eventually make their way into the documentation.  Please        treat the information here with caution, it has often not been        verified.</p>    </description>  </header>  <body>    <summary objsummary="localtoc"/>      <s1 title="How can I load configuration files for a class that might be used outside of a web-app?" type="faq">        <description>          I have a class needs to load a configuration file.  This class is          independent of the ServletApplication, it could be deployed in a web          application or someplace else.  What is the best way to allow my          class to access the configuration file?        </description>        <p>You can use <var>ClassLoader</var> to load your configration file from            anywhere in the classpath.  </p>        <p>A file from the classpath is always available to every           class using the ClassLoader.getResourceAsStream method.  So you don't           need to pass around any servlet context information.</p>                <p>The classpath also gives you a good deal of options of how to package           your files.  You can put them in jars in <var>WEB-INF/lib</var> or in the          <var>WEB-INF/classes</var> directory, or even in a jar file in          <var>$RESIN_HOME/lib</var>.</p>        <p>The basic call would be:</p>        <example>ClassLoader loader = Thread.currentThread().getContextClassLoader();InputStream is = loader.getResourceAsStream("config/myconfig.xml");        </example>        <p>The classpath is used to find the file, and the first one          found is used. An example of the search order for the above          example is:</p>        <ol>          <li>$RESIN_HOME/lib/anyjar.jar!/config/myconfig.xml          </li><li>WEB-INF/classes/config/myconfig.xml          </li><li>WEB-INF/lib/anyjar.jar!/config/myconfig.xml        </li></ol>                </s1>  </body></document>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?