Comments (7)
Is there a way for pf4j to search classes not in the root of jar but in a subfolder of it?
Sure.
Take a look at PluginClasspath and its implementations like DevelopmentPluginClasspath.
from pf4j-spring.
Thank you for your answer.
Why doesn't JarPluginLoader
use PluginClasspath
? It seems the way to load class from a jar that hasn't the standard structure, for example like the spring-executable-jar.
from pf4j-spring.
Why doesn't JarPluginLoader use PluginClasspath?
JarPluginLoader
loads plugins in JAR format. The layout of a JAR file is standard. Sure, in the end I think that we can force the use of PluginClasspath
also in JarPluginLoader
but my feeling is that you use spring-executable-jar
in a non natural way (maybe I am wrong).
I am not familiar with Spring Boot but my question is why do you need to use a spring-executable-jar
instead of classic jar
file for your plugins. In my opinion a spring-executable-jar
has a clear semantic and a well defined scenario. Even the name says that it's executable (it contains a main class inside) which doesn't make sense when it comes to plugins
In the end, this spring-executable-jar
is very similar with a standard ZIP file (almost the same layout) used by default by PF4J to represent a plugin. In the current version of PF4J, each plugin in ZIP format is extracted in a directory before it's loaded, but I think that it will be nice to have an option to not unpack the zip and use it as such. In this mode we can model a spring-executable-jar
as a standard zip
plugin file but with a custom file extension name.
When I see a file with extension .jar
my expectation is that I have to deal with a standard layout.
from pf4j-spring.
In spring boot application, the natural way to build a jar is just the spring-executable-jar
.
As you properly point out, it's a nonsense to have an executable file to load as a plugin. It's true, but spring boot
is not only a way to run app standalone, by now it's also the standard way to develop using spring framework, because it semplifies the setup and reduces the boilerplate.
In my context, plugins won't developed by me, but by 3rd parties and a java plugin mechanics, nowadays, must necessarily support spring boot.
Ok, I could say to plugin developers: "you can develop through spring framework, but you should build a traditional jar". Ok, it's easy, because spring boot produces, at the end of the build phase, both jars: the spring-executable-jar
and the classic jar, as well.
So, why do I insist on spring-executable-jar
? Because spring-executable-jar
is a fat jar that contains natively all libs. Whereas, pf4j requires a standard jar but enriched and assembled with all libs. I should ask to all 3rd parties to customize their build process in order to produce a pf4j compliant jar. Is it right?
I think pf4j should be compliant to the standard way to develop app in spring not viceversa, and in my view it means:
- to have a plugin loader for
spring-executable-jar
- to instanciate all controllers, services and beans defined by plugin.
The JarPluginLoader
could work as now (applying to all *.jar files), and using a special PluginClasspath if it recognizes the spring boot structure.
from pf4j-spring.
Of course, I don't want to convince you to not use spring-executable-jar
.
By default (current implementation), PF4J doesn't come with support for a such type of jar but PF4J is very flexible and it allows you to configure every aspect.
So, the fast solution for you is to create a SpringBootPluginLoader
that probably will extends JarPluginLoader
, and to override the load
method. After this you can inject this loader in PF4J.
Other variant is what I said in my previous comment:
In the end, this spring-executable-jar is very similar with a standard ZIP file (almost the same layout) used by default by PF4J to represent a plugin. In the current version of PF4J, each plugin in ZIP format is extracted in a directory before it's loaded, but I think that it will be nice to have an option to not unpack the zip and use it as such. In this mode we can model a spring-executable-jar as a standard zip plugin file but with a custom file extension name.
Any contribution (PR) is welcome.
If you have other concrete ideas, I'm ready to listen.
from pf4j-spring.
I have personally used pf4j in some of my projects with Spring Boot. I think what @decebals is saying about plugins not being executable makes complete sense. A plugin at the end of the day is a contract implementation. So they you can actually lay down some guidelines for the plugin developers on how it should be packaged. That is exactly what we did in our projects. I understand that using a .jar file is more native to Java and no extraction is required, but like we already know the Spring Boot executable is a complex beast in itself.
from pf4j-spring.
I'm trying to understand what happens under the hood of the spring boot classloader. I agree with you, it's complex enough, but "we should try, not because it's easy but because it's hard" :)
I'll let you know when I have some news.
from pf4j-spring.
Related Issues (20)
- update dependencies to newest spring 5.+ versions HOT 1
- Concrete bean could not be received from the application context HOT 1
- SpringPlugin start/stop/start results in Exception HOT 2
- Loading plugin on-runtime : Ambiguous hander methods mapped & ConcurrentModificationException when unregistering routes
- I use it SpringPluginManager, It seems to be a single case. HOT 4
- How to update the βList<Greeting>β while some plugins unloaded and deleted? HOT 4
- How to add integration tests for the plugin?
- self contained example HOT 1
- Jpa in plug-in not working HOT 1
- Hi author, Can I send a pull request to PF4J-Spring to support the Spring parent-child context οΌ
- Injecting beans from plugin in application doesn't work HOT 2
- run exception on pf4j-spring demo
- pf4j plugin needs to refresh and detect changes automatically with spring HOT 6
- How to get this repo versions release notes? HOT 2
- Problems with Using Pf4j-Spring HOT 1
- The real implementation cannot be accessed through the api interface. HOT 2
- When 'spring-boot-devtools' is introduced in the project, the extensions are not available. HOT 2
- How do you extend with kafka HOT 1
- Retrieve Resource from Inside Plugin HOT 1
- When will plan support Spring6.x ? HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pf4j-spring.