Note that there are some explanatory texts on larger screens.

plurals
  1. POGroovy resource from classpath not loaded
    primarykey
    data
    text
    <p>Good day everyone.</p> <p>I am using spock framework for testing in my groovy project(IDE - Intellij Idea 12.6). My spock specification class pass filename to groovy object for processing (that file is in classpath for sure), but when i try to get that file this way</p> <pre><code> def resource = getClass().getClassloader().getResourceAsStream(filepath) assert resource != null : "No input stream found for path ${filepath}" def rootNode = new XmlParser().parse(resource) </code></pre> <p>Then <code>resource == null</code>.</p> <p>I tried debugging and in Expression Evaluation windows this code <code>getClass().getResource(fileName)</code> returns resource.</p> <p>I tried to check which classloader used in first case (in class with the code) and in second case (Expression Evaluation window). </p> <p>In first case classloader was <code>sun.misc.Launcher$AppClassLoader@18dabf1</code>, but in Expression Evaluation window classloader was <code>groovy.lang.GroovyClassLoader$InnerLoader@1e69757</code> I suppose that's the reason my resource was null. </p> <p>Can someone guide me about what I am doing wrong and how can I load that resource file ?</p> <p><strong>UPDATE:</strong></p> <p>Changed the way resource file was parsed. When <code>filepath</code> - full path to file this works, but if <code>filepath</code> is just file name and that file in classpath then <code>resource == null</code></p> <p><strong>UPDATE2</strong>:</p> <p>Change the way resource file loaded, clean up dependencies bit and all is working, I guess yesterday just wasn't my day. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload