Dear ivyteam

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.

alt text

But if we try to load the class from the jar (using ClassLoader#loadClass) we get a NoClassDefFound exception. Is there any way to get such a structure to work? Maybe with some class loader magic?

Best regards Lars

asked 09.07.2019 at 07:31

Lars%20Tuchel's gravatar image

Lars Tuchel
(suspended)
accept rate: 60%

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.

(10.07.2019 at 08:27) vagabond vagabond's gravatar image

Hi Lars

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.

Can you tell me the use case behing your question?

Regards

Reto Weiss, Axon.ivy Support

link

answered 09.07.2019 at 11:28

Reto%20Weiss's gravatar image

Reto Weiss ♦♦
4.9k202857
accept rate: 74%

Hi Reto

Ok, I see. Thank you, Reto.

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.

(10.07.2019 at 02:12) Lars Tuchel Lars%20Tuchel's gravatar image

Hi Lars

How have you planed to inject the implementation into the project then? Or how can the project get an instance of the implementation?

(10.07.2019 at 02:37) Reto Weiss ♦♦ Reto%20Weiss's gravatar image

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

(10.07.2019 at 04:27) Lars Tuchel Lars%20Tuchel's gravatar image

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.

(11.07.2019 at 02:51) Reto Weiss ♦♦ Reto%20Weiss's gravatar image

If you want to discuss this scenario in depth we can do a Skype call or organize a short meeting

(11.07.2019 at 02:53) Reto Weiss ♦♦ Reto%20Weiss's gravatar image
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×147
×2

Asked: 09.07.2019 at 07:31

Seen: 1,295 times

Last updated: 11.07.2019 at 02:53