<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: How to load resources in IvyProject from Java?</title><link>https://answers.axonivy.com/questions/2872/how-to-load-resources-in-ivyproject-from-java</link><description>&lt;p&gt;In typical Java EE maven project I put resources in src/main/resources and access files with getResourceAsStream().&lt;/p&gt;
&lt;p&gt;How to work relative to the current class has been dicussed in  &lt;a href="https://discourse.axonivy.io/t/how-to-read-file-in-resources-folder-or-webcontent-in-an-axon-ivy-project/135/2" title="this thread"&gt;this thread&lt;/a&gt;. However, I would need an absolute way to access resources.  &lt;/p&gt;
&lt;p&gt;Background of this question is that I would like to use &lt;a href="http://owner.aeonbits.org/" title="owner"&gt;owner&lt;/a&gt; config &lt;a href="http://owner.aeonbits.org/docs/loading-strategies/" title="with fallback"&gt;with fallback&lt;/a&gt; to a classpath property file.&lt;/p&gt;
&lt;p&gt;Thanks for help.&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/2872/how-to-load-resources-in-ivyproject-from-java" rel="self"></atom:link><language>en</language><lastBuildDate>Tue, 24 Oct 2017 06:36:51 -0400</lastBuildDate><item><title>Comment by adamf on Lars Tuchel's answer</title><link>https://answers.axonivy.com/questions/2872/how-to-load-resources-in-ivyproject-from-java#2926</link><description>&lt;p&gt;Hi &lt;a href="https://answers.axonivy.com/users/17/reguel-wermelinger"&gt;&lt;a href="https://answers.axonivy.com/users/17/reguel-wermelinger"&gt;@Reguel&lt;/a&gt;&lt;/a&gt;, yes it includes the resources in IAR file. But it looks like in the engine only resources in one of the default src_ folders are considered. It does not matter so much, as there is no real use case for this in Ivy. And one can cope with having java classes mixed with resources if one really needs them.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">adamf</dc:creator><pubDate>Tue, 24 Oct 2017 06:36:51 -0400</pubDate><guid>https://answers.axonivy.com/questions/2872/how-to-load-resources-in-ivyproject-from-java#2926</guid></item><item><title>Comment by Reguel Wermelinger on Lars Tuchel's answer</title><link>https://answers.axonivy.com/questions/2872/how-to-load-resources-in-ivyproject-from-java#2888</link><description>&lt;p&gt;can you check whether the resource really exist in the built IAR file? 
Maybe it is not because some files are filtered by default. You may want to play around with the related parameters of the maven plugin to steer the file inclusion in ivy archives.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://axonivy.github.io/project-build-plugin/release/7.0/pack-iar-mojo.html"&gt;http://axonivy.github.io/project-build-plugin/release/7.0/pack-iar-mojo.html&lt;/a&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Tue, 26 Sep 2017 09:46:59 -0400</pubDate><guid>https://answers.axonivy.com/questions/2872/how-to-load-resources-in-ivyproject-from-java#2888</guid></item><item><title>Comment by adamf on Lars Tuchel's answer</title><link>https://answers.axonivy.com/questions/2872/how-to-load-resources-in-ivyproject-from-java#2884</link><description>&lt;p&gt;This approach using maven resource still does not work on the stand alone  engine for me. Please check that this approach works also on  engine before accepting.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">adamf</dc:creator><pubDate>Mon, 25 Sep 2017 09:11:14 -0400</pubDate><guid>https://answers.axonivy.com/questions/2872/how-to-load-resources-in-ivyproject-from-java#2884</guid></item><item><title>Comment by Lars Tuchel on Lars Tuchel's answer</title><link>https://answers.axonivy.com/questions/2872/how-to-load-resources-in-ivyproject-from-java#2879</link><description>&lt;p&gt;Hi &lt;a href="https://answers.axonivy.com/users/869/adamf"&gt;&lt;a href="https://answers.axonivy.com/users/869/adamf"&gt;@adamf&lt;/a&gt;&lt;/a&gt; 
When you build your project with maven, make sure you add your folder as resources folder in the pom.xml. See &lt;a href="https://maven.apache.org/plugins/maven-resources-plugin/examples/resource-directory.html"&gt;https://maven.apache.org/plugins/maven-resources-plugin/examples/resource-directory.html&lt;/a&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Lars Tuchel</dc:creator><pubDate>Fri, 22 Sep 2017 10:15:17 -0400</pubDate><guid>https://answers.axonivy.com/questions/2872/how-to-load-resources-in-ivyproject-from-java#2879</guid></item><item><title>Comment by adamf on adamf's question</title><link>https://answers.axonivy.com/questions/2872/how-to-load-resources-in-ivyproject-from-java#2877</link><description>&lt;p&gt;The "ivy way" is probably to use the &lt;a href="https://developer.axonivy.com/doc/latest/DesignerGuideHtml/ivy.configuration.html"&gt;configuration system&lt;/a&gt; for configs and other resources as texts or images to &lt;a href="https://developer.axonivy.com/doc/latest/DesignerGuideHtml/ivy.cms.html"&gt;CMS system&lt;/a&gt; and use Ivy.cms().getContentObject(path) ?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">adamf</dc:creator><pubDate>Thu, 21 Sep 2017 10:28:06 -0400</pubDate><guid>https://answers.axonivy.com/questions/2872/how-to-load-resources-in-ivyproject-from-java#2877</guid></item><item><title>Comment by adamf on Lars Tuchel's answer</title><link>https://answers.axonivy.com/questions/2872/how-to-load-resources-in-ivyproject-from-java#2875</link><description>&lt;p&gt;Hi &lt;a href="https://answers.axonivy.com/users/41/lars-tuchel"&gt;&lt;a href="https://answers.axonivy.com/users/41/lars-tuchel"&gt;@Lars&lt;/a&gt;&lt;/a&gt;, your example works in Developer, but when deploying on Axon.ivy Engine it throws  a NPE (Cannot find the resource). Anything to take care of when deploying on Axon.ivy Engine?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">adamf</dc:creator><pubDate>Wed, 20 Sep 2017 15:31:52 -0400</pubDate><guid>https://answers.axonivy.com/questions/2872/how-to-load-resources-in-ivyproject-from-java#2875</guid></item><item><title>Answer by Lars Tuchel</title><link>https://answers.axonivy.com/questions/2872/how-to-load-resources-in-ivyproject-from-java/2874</link><description>&lt;p&gt;Hi Adam&lt;/p&gt;
&lt;p&gt;Create a new folder in your axonivy project, add the folder to your classpath (as shown below) and then make sure you path starts with a forward-slash (e.g. &lt;code&gt;/path/to/my/file.txt&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;&lt;img alt="alt text" src="https://answers.axonivy.com/upfiles/add_src.png"&gt;&lt;/p&gt;
&lt;p&gt;Also here's a sample project: &lt;a href="https://drive.google.com/file/d/0B3V8Sh7Fl7FXWHRxcEw2T29PdkU/view?usp=sharing"&gt;https://drive.google.com/file/d/0B3V8Sh7Fl7FXWHRxcEw2T29PdkU/view?usp=sharing&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Cheers
Lars&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Lars Tuchel</dc:creator><pubDate>Wed, 20 Sep 2017 13:02:58 -0400</pubDate><guid>https://answers.axonivy.com/questions/2872/how-to-load-resources-in-ivyproject-from-java/2874</guid></item><item><title>Comment by adamf on adamf's question</title><link>https://answers.axonivy.com/questions/2872/how-to-load-resources-in-ivyproject-from-java#2873</link><description>&lt;p&gt;So working with relative path annotating my owner config with @Config.Sources({"classpath:./MyConfig.properties"}), but this requires having property file in same directory as java files.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">adamf</dc:creator><pubDate>Wed, 20 Sep 2017 08:34:04 -0400</pubDate><guid>https://answers.axonivy.com/questions/2872/how-to-load-resources-in-ivyproject-from-java#2873</guid></item></channel></rss>