tag:infinitekind.tenderapp.com,2009-01-14:/discussions/moneydance-development/1391-classgetresource-returns-nullInfinite Kind: Discussion 2018-10-18T14:05:02Ztag:infinitekind.tenderapp.com,2009-01-14:Comment/390345792016-01-28T20:56:01Z2016-01-28T20:56:01ZClass::getResource returns null<div><p>Hi Jeffrey,</p>
<p>I believe the classloader that Moneydance uses to load resources
from extension bundles requires the full path to anything that it
loads, probably with a leading "/" on the front. If you try to load
it that way, does it work?</p>
<p>Thanks!</p>
<p>Sean Reilly<br>
Developer, The Infinite Kind<br>
<a href="http://infinitekind.com">http://infinitekind.com</a></p></div>Sean Reillytag:infinitekind.tenderapp.com,2009-01-14:Comment/390345792016-01-29T16:20:52Z2016-01-29T16:21:27ZClass::getResource returns null<div><p>It still doesn't work. I put the following into
<code>init</code>:</p>
<pre>
<code> System.err.println(getClass().getResource("meta_info.dict"));
System.err.println(getClass().getClassLoader()
.getResource("com/moneydance/modules/features/myfeaturename/meta_info.dict"));
System.err.println(getClass().getClassLoader()
.getResource("/com/moneydance/modules/features/myfeaturename/meta_info.dict"));
System.err.println(ClassLoader.getSystemClassLoader()
.getResource("com/moneydance/modules/features/myfeaturename/meta_info.dict"));
System.err.println(ClassLoader.getSystemClassLoader()
.getResource("/com/moneydance/modules/features/myfeaturename/meta_info.dict"));</code>
</pre>
<p>When I install my plugin into Moneydance, each line prints
<code>null</code>.</p>
<p>If I run</p>
<pre>
<code> public static void main(String[] args) {
new Main().init();
}</code>
</pre>
<p>from Eclipse or <code>java</code>, I get</p>
<pre>
<code>file:/com/moneydance/modules/features/myfeaturename/meta_info.dict
file:/com/moneydance/modules/features/myfeaturename/meta_info.dict
null
file:/com/moneydance/modules/features/myfeaturename/meta_info.dict
null</code>
</pre></div>Jefftag:infinitekind.tenderapp.com,2009-01-14:Comment/390345792016-01-29T16:38:23Z2016-01-29T16:38:23ZClass::getResource returns null<div><p>Ah, the meta_info.dict is treated differently when the extension
is packaged into the mxt file (which is just a jar/zip file). Can
you run "unzip -l myfeaturename.mxt" and check the paths of the
contents?</p>
<p>Thanks,<br>
Sean</p></div>Sean Reillytag:infinitekind.tenderapp.com,2009-01-14:Comment/390345792016-01-29T16:43:59Z2016-01-29T16:43:59ZClass::getResource returns null<div><p>
<code>/com/moneydance/modules/features/myfeaturename/meta_info.dict</code>
exists and all of the other resources I'm trying to access are in
the places I expect them to be.</p></div>Jefftag:infinitekind.tenderapp.com,2009-01-14:Comment/390345792016-01-29T16:48:46Z2016-01-29T16:48:46ZClass::getResource returns null<div><p>It looks like if I change <code>getResource</code> to
<code>getResourceAsStream</code> it'll work. Weird.</p></div>Jefftag:infinitekind.tenderapp.com,2009-01-14:Comment/390345792016-01-29T17:48:56Z2016-01-29T17:48:56ZClass::getResource returns null<div><p>This is actually becoming something of an issue. I'm trying to
use a library which relies on <code>ServiceLoader</code>s.
<code>ServiceLoader</code>s use
<code>ClassLoader::getResources</code>, which will always return
<code>null</code> in Moneydance.</p>
<p>Would it be possible to add plugin support for
<code>ClassLoader::getResources</code> and
<code>ClassLoader::getResource</code>?</p></div>Jeff