Resources.xhtml 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg">
  3. <head>
  4. <title>Resources</title>
  5. <link rel="stylesheet" type="text/css" href="docbook-epub.css"/>
  6. <link rel="stylesheet" type="text/css" href="kawa.css"/>
  7. <script src="kawa-ebook.js" type="text/javascript"/>
  8. <meta name="generator" content="DocBook XSL-NS Stylesheets V1.79.1"/>
  9. <link rel="prev" href="Overall-Index.xhtml" title="Index"/>
  10. <link rel="next" href="Types.xhtml" title="Types"/>
  11. </head>
  12. <body>
  13. <header/>
  14. <section class="sect1" title="Resources" epub:type="subchapter" id="Resources">
  15. <div class="titlepage">
  16. <div>
  17. <div>
  18. <h2 class="title" style="clear: both">Resources</h2>
  19. </div>
  20. </div>
  21. </div>
  22. <p>A resource is a file or other fixed data that an application may access.
  23. Resources are part of the application and are shipped with it, but are
  24. stored in external files. Examples are images, sounds,
  25. and translation (localization) of messages.
  26. In the Java world a resource is commonly bundled in the same jar file
  27. as the application itself.
  28. </p>
  29. <p class="synopsis" kind="Syntax"><span class="kind">Syntax</span><span class="ignore">: </span><a id="idm139667872034592" class="indexterm"/> <code class="function">resource-url</code> <em class="replaceable"><code>resource-name</code></em></p>
  30. <div class="blockquote">
  31. <blockquote class="blockquote">
  32. <p>Returns a <code class="literal">URLPath</code> you can use as a <code class="literal">URL</code>, or
  33. you can pass to it <code class="literal">open-input-file</code> to read the resource data.
  34. The <em class="replaceable"><code>resource-name</code></em> is a string which is passed to the
  35. <code class="literal">ClassLoader</code> of the containing module.
  36. If the module class is in a jar file, things will magically
  37. work if the resource is in the same jar file, and <em class="replaceable"><code>resource-name</code></em>
  38. is a filename relative to the module class in the jar.
  39. If the module is immediately evaluated, the <em class="replaceable"><code>resource-name</code></em> is resolved
  40. against the location of the module source file.
  41. </p>
  42. </blockquote>
  43. </div>
  44. <p class="synopsis" kind="Syntax"><span class="kind">Syntax</span><span class="ignore">: </span><a id="idm139667872027808" class="indexterm"/> <code class="function">module-uri</code></p>
  45. <div class="blockquote">
  46. <blockquote class="blockquote">
  47. <p>Evaluates to a special URI that can be used to access resources
  48. relative to the class of the containing module.
  49. The URI has the form <code class="literal">"class-resource://<em class="replaceable"><code>CurrentClass</code></em>/"</code>
  50. in compiled code, to allow moving the classes/jars.
  51. The current <code class="literal">ClassLoader</code> is associated with the URI, so accessing
  52. resources using the URI will use that <code class="literal">ClassLoader</code>.
  53. Therefore you should not create a <code class="literal">"class-resource:"</code> URI
  54. except by using this function or <code class="literal">resolve-uri</code>,
  55. since that might try to use the wrong <code class="literal">ClassLoader</code>.
  56. </p>
  57. <p>The macro <code class="literal">resource-url</code> works by using <code class="literal">module-uri</code>
  58. and resolving that to a normal <code class="literal">URL</code>.
  59. </p>
  60. </blockquote>
  61. </div>
  62. <p class="synopsis" kind="Syntax"><span class="kind">Syntax</span><span class="ignore">: </span><a id="idm139667872019712" class="indexterm"/> <code class="function">module-class</code></p>
  63. <div class="blockquote">
  64. <blockquote class="blockquote">
  65. <p>Evaluates to the containing module class, as a <code class="literal">java.lang.Class</code> instance.
  66. </p>
  67. </blockquote>
  68. </div>
  69. </section>
  70. <footer>
  71. <div class="navfooter">
  72. <p>
  73. Up: <a accesskey="u" href="Input-Output.xhtml">Input, output, and file handling</a></p>
  74. <p>
  75. Previous: <a accesskey="p" href="Pretty-printing.xhtml">Pretty-printing</a></p>
  76. </div>
  77. </footer>
  78. </body>
  79. </html>