2

I am going to create Java Application that can load external jar files at runtime by FileChooser. I am using Spring Framework, and I want to load jar file and its applicationContext.xml file and inject its dependencies dynamically. I tried to achieve this by OSGi, but it seems very complicated so that I am searching another appropriate variants.

I want to make something like Intellij IDEA plugin installation from the disk.

How can I do this? (After the jar file chosen restarting an application also accepted)

Xylian
  • 241
  • 2
  • 10
  • 1
    I extended code I had to write for a university lecture to a [plugin enabled application](https://github.com/RovoMe/PluginApplication) a couple of years ago that supports dependency injection and acts similar to OSGi but on a much simpler basis. Plugins should only be loaded if all required dependencies are available already. Exports and imports are declared in the jars `MANIFEST.MF` (similar to Java 9). The dependency injection is done on its own though and not via spring, though you might look at the code and maybe get an idea of how to achive what you need – Roman Vottner Jan 07 '18 at 22:03
  • Yes, for now It seems the only correct way for me. – Xylian Jan 07 '18 at 22:19

1 Answers1

0

I realy like your approach, unfortunately spring has lifecycles that are strict. As you might know, spring autowires "beans" only. Exactly one lifecycle registers the different bean candidates. After that lifecycle spring (by default) does not accept new classes.

You must use the spring-osgi.

If you only need the CDI part out of spring, you might like to use a different CDI like red hat's jboss server.

Grim
  • 1,938
  • 10
  • 56
  • 123