<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: Access Ivy project classloader on jar</title><link>https://answers.axonivy.com/questions/2337/access-ivy-project-classloader-on-jar</link><description>&lt;p&gt;Hi all&lt;/p&gt;
&lt;p&gt;I'm using a htmlUserDialog wich JSF and i have a jsf custom tag, i build and put it on webapp folder of server. this is a custom tag that i will use on my xhtml. this tag somehow is a jsf event listener, it listen system event of jsf (ex: PostAddToView, PreRenderView,...)&lt;/p&gt;
&lt;p&gt;Sometime when i start ivy engine (via Windows services), i got exception:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ch.ivyteam.ivy.environment.EnvironmentNotAvailableException: Access to ivy environment outside a process request thread is not possible.
    Current thread: Thread[http-nio-8082-exec-1,5,main]
        at ch.ivyteam.ivy.environment.Ivy.getIvy(Ivy.java:574)
        at ch.ivyteam.ivy.environment.Ivy.getEnvironmentData(Ivy.java:553)
        at ch.ivyteam.ivy.environment.Ivy.getEnvironmentData(Ivy.java:548)
        at ch.ivyteam.ivy.environment.Ivy.request(Ivy.java:242)
        at ch.axonivy.fintech.guiframework.component.GuiEventListenerFactoryServiceProvider.getProjectClassLoader(GuiEventListenerFactoryServiceProvider.java:67)
        at ch.axonivy.fintech.guiframework.component.GuiEventListenerFactoryServiceProvider.getFactory(GuiEventListenerFactoryServiceProvider.java:32)
        at ch.axonivy.fintech.guiframework.component.GuiEventListenerComponent.&amp;lt;init&amp;gt;(GuiEventListenerComponent.java:46)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at java.lang.Class.newInstance(Class.java:442)
        at org.apache.myfaces.application.ApplicationImpl.createComponent(ApplicationImpl.java:1469)
        at javax.faces.application.ApplicationWrapper.createComponent(ApplicationWrapper.java:129)
        at org.apache.myfaces.extensions.validator.core.factory.ExtValApplicationWrapper.createComponent(ExtValApplicationWrapper.java:84)
        at javax.faces.application.ApplicationWrapper.createComponent(ApplicationWrapper.java:129)
        at org.apache.myfaces.view.facelets.compiler.FaceletsCompilerSupport.loadLibraries(FaceletsCompilerSupport.java:141)
        at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.loadLibraries(FaceletViewDeclarationLanguage.java:2526)
        at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.createCompiler(FaceletViewDeclarationLanguage.java:2172)
        at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.initialize(FaceletViewDeclarationLanguage.java:2464)
        at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.&amp;lt;init&amp;gt;(FaceletViewDeclarationLanguage.java:309)
        at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguageStrategy.&amp;lt;init&amp;gt;(FaceletViewDeclarationLanguageStrategy.java:52)
        at org.apache.myfaces.view.ViewDeclarationLanguageFactoryImpl.initialize(ViewDeclarationLanguageFactoryImpl.java:104)
        at org.apache.myfaces.view.ViewDeclarationLanguageFactoryImpl.getViewDeclarationLanguage(ViewDeclarationLanguageFactoryImpl.java:73)
        at org.apache.myfaces.application.ViewHandlerImpl.getViewDeclarationLanguage(ViewHandlerImpl.java:183)
        at javax.faces.application.ViewHandlerWrapper.getViewDeclarationLanguage(ViewHandlerWrapper.java:133)
        at org.apache.myfaces.shared.application.DefaultViewHandlerSupport.checkResourceExists(DefaultViewHandlerSupport.java:569)
        at org.apache.myfaces.shared.application.DefaultViewHandlerSupport.handleSuffixMapping(DefaultViewHandlerSupport.java:507)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In my jar file, i need to access to ivy project class loader, so i have this line:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; ClassLoader cl = Ivy.request().getProject().getProjectClassLoader();
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I have a interface in this jar so i need to get class loader to find which class (from ivy project) is implementing my interface (vis ServiceLoader)&lt;/p&gt;
&lt;p&gt;I guess my jar is started before ivy initialize its environment. 
So how can i solve it ?&lt;/p&gt;
&lt;p&gt;P/S: when i try to start some more times, my engine can start but this exception is quite annoying imo&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/2337/access-ivy-project-classloader-on-jar" rel="self"></atom:link><language>en</language><lastBuildDate>Thu, 29 Dec 2016 14:27:37 -0500</lastBuildDate><item><title>Answer by Flavio Sadeghi</title><link>https://answers.axonivy.com/questions/2337/access-ivy-project-classloader-on-jar/2340</link><description>&lt;p&gt;&lt;code&gt;Ivy.request()&lt;/code&gt; is only available in a http-request. As you probably know. On engine start the context is not set up. &lt;/p&gt;
&lt;p&gt;Maybe you could initialize your state(s) within the first request. Please keep in mind that the jsf-initialization is NOT done for each project/pmv - just one for the engine.&lt;/p&gt;
&lt;p&gt;Anyway, it's hard with just the snipped of a Stacktrace to give valuable feedback. Therefore, could you create a demo project?&lt;/p&gt;
&lt;p&gt;Ps. There are investigations (tech stories) to provide contexts for each pmv-set, see  &lt;a href="http://developer.axonivy.com/extend/"&gt;here (public)&lt;/a&gt; and &lt;a href="https://jira.axonivy.com/confluence/display/IVYTEAM/Improve+ivy+extendability"&gt;here (internal)&lt;/a&gt;. I think this would help a lot to create custom features for ivy...&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Flavio Sadeghi</dc:creator><pubDate>Thu, 29 Dec 2016 14:27:37 -0500</pubDate><guid>https://answers.axonivy.com/questions/2337/access-ivy-project-classloader-on-jar/2340</guid></item></channel></rss>