1

I'm creating a Java web application, making use of CDI. My War includes various Jar files that are bean sources (including the META-INF/beans.xml file). My beans are automatically discovered when running inside a Java EE container like JBoss (I'm currently using JBoss AS 7.1.1). This much is working well.

I want to be able to extend the web application, ideally by allowing it to load classes from Jar files stored in a configurable location (so at a location specified by a system property). This too is fine, since I can use a ClassLoader to resolve classes and resources. What I'm missing is the ability to have CDI scan these external Jar files and include their beans.

This would allow my application to host plug-in functionality including new REST resources. I don't mind if I had to restart the application for it to pick up classes and resources contained within these external Jar files.

I can see no way of achieving this. Is this even something that should be attempted in this kind of environment?

William
  • 66
  • 5

1 Answers1

1

I can see no way of achieving this.

You actually have two options:

  1. Use the CDI extension mechanism to work with beans / bean-archives at startup time and to modify them in the way you want. Have a look at the examples provided in the documentation, this should give you a start.
  2. Work with the BeanManager at execution time. Have a look at this similar question.
Community
  • 1
  • 1
Jan Groth
  • 14,039
  • 5
  • 40
  • 55
  • Thanks. I think I see a potential approach. I've created a CDI extension. It @Observes the AfterBeanDiscovery event and responds by searching for plug-ins and registering them with the event. This does make the plug-in beans available via the BeanMananager. I need to look further to see if I can register any REST resources that might exist in the plug-in, but for basic functionality it seems to solve some of my problem. – William Jul 12 '12 at 13:18