<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: Loading classes from WEB-INF/lib</title><link>https://answers.axonivy.com/questions/3879/loading-classes-from-web-inf-lib</link><description>&lt;p&gt;Dear ivyteam&lt;/p&gt;
&lt;p&gt;In our project we'd like to have the following structure: Our ivy project contains a jar which has some Java interfaces. Then we'd like the implementations for these interfaces in another external jar that we can deploy independently. Our idea was to put into the WEB-INF/lib folder. &lt;/p&gt;
&lt;p&gt;&lt;img alt="alt text" src="https://answers.axonivy.com/upfiles/example.png"&gt;&lt;/p&gt;
&lt;p&gt;But if we try to load the class from the jar (using &lt;code&gt;ClassLoader#loadClass&lt;/code&gt;) we get a &lt;code&gt;NoClassDefFound&lt;/code&gt; exception. Is there any way to get such a structure to work? Maybe with some class loader magic?&lt;/p&gt;
&lt;p&gt;Best regards
Lars&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/3879/loading-classes-from-web-inf-lib" rel="self"></atom:link><language>en</language><lastBuildDate>Thu, 11 Jul 2019 02:53:04 -0400</lastBuildDate><item><title>Comment by Reto Weiss on Reto Weiss's answer</title><link>https://answers.axonivy.com/questions/3879/loading-classes-from-web-inf-lib#3889</link><description>&lt;p&gt;If you want to discuss this scenario in depth we can do a Skype call or organize a short meeting&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reto Weiss</dc:creator><pubDate>Thu, 11 Jul 2019 02:53:04 -0400</pubDate><guid>https://answers.axonivy.com/questions/3879/loading-classes-from-web-inf-lib#3889</guid></item><item><title>Comment by Reto Weiss on Reto Weiss's answer</title><link>https://answers.axonivy.com/questions/3879/loading-classes-from-web-inf-lib#3888</link><description>&lt;p&gt;What if the implementation is in one project (lets say 'customer') and the interface is in another one (lets say 'standard'). Then the 'customer' project depends on 'standard'. Now 'standard' could evaluate all projects that depend on it and read the di config file from them and install this info into Guice.  Then 'standard' shoud be able to inject an implementation of the interface into itselft. 
Be aware: The you have to ensure that the implementation class needs to be loaded with the classlaoder from 'customer' and not with the class laoder from 'standard'. But this should be possible.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reto Weiss</dc:creator><pubDate>Thu, 11 Jul 2019 02:51:21 -0400</pubDate><guid>https://answers.axonivy.com/questions/3879/loading-classes-from-web-inf-lib#3888</guid></item><item><title>Comment by vagabond on Lars Tuchel's question</title><link>https://answers.axonivy.com/questions/3879/loading-classes-from-web-inf-lib#3886</link><description>&lt;p&gt;This is an interesiting problem. Suppose we could have a way by some ClassLoader black magic, how do you plan to deal with situation that different IARs depend on different version of the interface JARs. How to load the correct impl of the correct version? Something like versioning using package name may create a mess, I guess.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">vagabond</dc:creator><pubDate>Wed, 10 Jul 2019 08:27:44 -0400</pubDate><guid>https://answers.axonivy.com/questions/3879/loading-classes-from-web-inf-lib#3886</guid></item><item><title>Comment by Lars Tuchel on Reto Weiss's answer</title><link>https://answers.axonivy.com/questions/3879/loading-classes-from-web-inf-lib#3885</link><description>&lt;p&gt;There's a config file, where we can specify which implementation to use on a given environment and then we use guice to configure the inferfaces/implementations&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Lars Tuchel</dc:creator><pubDate>Wed, 10 Jul 2019 04:27:25 -0400</pubDate><guid>https://answers.axonivy.com/questions/3879/loading-classes-from-web-inf-lib#3885</guid></item><item><title>Comment by Reto Weiss on Reto Weiss's answer</title><link>https://answers.axonivy.com/questions/3879/loading-classes-from-web-inf-lib#3884</link><description>&lt;p&gt;Hi Lars&lt;/p&gt;
&lt;p&gt;How have you planed to inject the implementation into the project then? Or how can the project get an instance of the implementation?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reto Weiss</dc:creator><pubDate>Wed, 10 Jul 2019 02:37:11 -0400</pubDate><guid>https://answers.axonivy.com/questions/3879/loading-classes-from-web-inf-lib#3884</guid></item><item><title>Comment by Lars Tuchel on Reto Weiss's answer</title><link>https://answers.axonivy.com/questions/3879/loading-classes-from-web-inf-lib#3883</link><description>&lt;p&gt;Hi Reto&lt;/p&gt;
&lt;p&gt;Ok, I see. Thank you, Reto.&lt;/p&gt;
&lt;p&gt;Basically we have some external services for which we define the interfaces in our projects. Then we'd like other third-party developers (that might not use ivy) to implement these interfaces. The approach works with both the interfaces and the implementation in WEB-INF/lib, but we would have preferred to deliver our interfaces directly with our iars.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Lars Tuchel</dc:creator><pubDate>Wed, 10 Jul 2019 02:12:32 -0400</pubDate><guid>https://answers.axonivy.com/questions/3879/loading-classes-from-web-inf-lib#3883</guid></item><item><title>Answer by Reto Weiss</title><link>https://answers.axonivy.com/questions/3879/loading-classes-from-web-inf-lib/3882</link><description>&lt;p&gt;Hi Lars&lt;/p&gt;
&lt;p&gt;This will not work because the class loader hierarchy is exactly the opposite. This means the projects class loader has the web application class loader as parent. E.g. the project can load classes from WEB-INF/lib but not vice versa. &lt;/p&gt;
&lt;p&gt;Can you tell me the use case behing your question? &lt;/p&gt;
&lt;p&gt;Regards&lt;/p&gt;
&lt;p&gt;Reto Weiss, Axon.ivy Support&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reto Weiss</dc:creator><pubDate>Tue, 09 Jul 2019 11:28:32 -0400</pubDate><guid>https://answers.axonivy.com/questions/3879/loading-classes-from-web-inf-lib/3882</guid></item></channel></rss>