pf4j-spring icon indicating copy to clipboard operation
pf4j-spring copied to clipboard

Add Dependency in Plugin application

Open MohankumarD opened this issue 6 years ago • 19 comments

Hi Decebals, I am facing the same issue, can you please help on this how to add a dependency for third-party jar..

Also added dependency in assambly.xml file:

<includes>
    <include>org.pf4j:*</include>
    <include>com.googlecode.json-simple:*</include>
</includes>

Originally posted by @MohankumarD in https://github.com/pf4j/pf4j-spring/issues/19#issuecomment-463591048

MohankumarD avatar Feb 14 '19 11:02 MohankumarD

From #19:

Can you add more detail please? Can you share with us the plugin's pom.xml? Maybe you create a thin jar and not a fat jar. Please take a look at your plugin's jar and see if the find the POI's classes.

Your plugins system uses .zip or .jar format to pack your plugins?

decebals avatar Feb 14 '19 14:02 decebals

Refer plugin pom.xml file, yes i have created thin jar file for testing. For testing I have used Simple-Json as third pary lib. pom.xml.txt

Yes my plugin system as .jar format

MohankumarD avatar Feb 14 '19 17:02 MohankumarD

Probably your plugins packaging approach is based on demo module from this project (pf4j-spring). Please take a look to demo from pf4j (https://github.com/pf4j/pf4j/tree/master/demo/plugins) because the entire plugins packaging process is simplified for jar format. Leave a message if you encounter problems.

decebals avatar Feb 14 '19 17:02 decebals

Yes, I am referring pf4j-spring. Will you able to tell me what is the mistake in the existing plugin project.

When I use plugin application as ZIP file, its working fine. Help me on JAR

MohankumarD avatar Feb 15 '19 02:02 MohankumarD

Will you able to tell me what is the mistake in the existing plugin project.

I didn't say that something is wrong with demo project from pf4j-spring. I say that it is an old version of demo project from pf4j, and it uses assembly.xml to pack the plugin in a zip file. The demo from pf4j doesn't use an assembly.xml and pack the plugin in a jar file. My recommendation is to try to run demo project (using run-demo.sh or run-demo.bat script) first, and after this to continue with your project. In this mode I can help you more.

decebals avatar Feb 15 '19 18:02 decebals

I was going to enter an issue or try to ask a question that seems related to the above, so I'll ask it here for now:

Can you elaborate on if we should be using .zip or .jar plugin files? The pf4j-spring demo builds .zip files, but the run-demo.sh script doesn't use them...it copies the .jar files instead. When I try copying the .zip files instead, the app fails to find the plugin class implementation. I notice that the .zip files do have additional dependencies in them, so maybe in general they are needed.

I think maybe what you're saying is that the main pf4j demo shows the way to build plugins as .jar files that include the dependencies. Is that right? Could you possibly update the pf4j-spring demo to demonstrate the most correct way to do things? If not, maybe you could provide some information in a more obvious place regarding just how to best get going with your project if your demo isn't the best way.

sljinlet avatar Feb 17 '19 19:02 sljinlet

I believe I've done what I asked to have the author do above. I've submitted a pull request for this work.

sljinlet avatar Feb 17 '19 20:02 sljinlet

Will you able to tell me what is the mistake in the existing plugin project.

I didn't say that something is wrong with demo project from pf4j-spring. I say that it is an old version of demo project from pf4j, and it uses assembly.xml to pack the plugin in a zip file. The demo from pf4j doesn't use an assembly.xml and pack the plugin in a jar file. My recommendation is to try to run demo project (using run-demo.sh or run-demo.bat script) first, and after this to continue with your project. In this mode I can help you more.

I have executed the run-demo.bat file and successfully executed. Please guide me on how do I check the demo project.

MohankumarD avatar Feb 18 '19 06:02 MohankumarD

I fixed the run-demo scripts. Please run-demo again. @MohankumarD If everything is OK you will see in in console the messages printed by extensions: image

Can you elaborate on if we should be using .zip or .jar plugin files?

pf4j-demo uses the .jar format plugins and pf4j-spring-demo uses the .zip format plugins. Both plugins format (.jar and .zip) are OK. For .zip it's a little bit extra work but you will see all jar dependencies in lib directory. For .jar it's much simple from plugin packaging point of view (no assembly.xml file) but all classes files from all dependencies are merged in a big (fat) jar. Everything depends only by your preferences,

decebals avatar Feb 18 '19 23:02 decebals

I fixed the run-demo scripts. Please run-demo again. @MohankumarD If everything is OK you will see in in console the messages printed by extensions: image

Can you elaborate on if we should be using .zip or .jar plugin files?

pf4j-demo uses the .jar format plugins and pf4j-spring-demo uses the .zip format plugins. Both plugins format (.jar and .zip) are OK. For .zip it's a little bit extra work but you will see all jar dependencies in lib directory. For .jar it's much simple from plugin packaging point of view (no assembly.xml file) but all classes files from all dependencies are merged in a big (fat) jar. Everything depends only by your preferences,

Not able to build plugin1 and 2 projects “mvn clear package”

MohankumarD avatar Feb 19 '19 06:02 MohankumarD

@MohankumarD Just run run-demo.bat (for Windows) and run-demo.sh (for Linux) from root of pf4j-spring project. If you don't succeed please paste last lines here to take a look.

decebals avatar Feb 19 '19 08:02 decebals

@decebals If I execute run-demo.bat, it's working fine and I am able to get the result as specified. But I want to make some changes in Plugin1 app alone and create a build. Let me know the changes need to be done in POM file for a successful build.

MohankumarD avatar Feb 20 '19 06:02 MohankumarD

@MohankumarD And where is the problem? If you take a look of plugin1's pom.xml you will see that this plugin contains a dependency to commons-lang:

<dependency>
    <groupId>commons-lang</groupId>
    <artifactId>commons-lang</artifactId>
    <version>2.6</version>
</dependency>

You can add what dependencies you want. At the end, to create the new plugin distribution (plugin.zip) you must:

  • cd pf4j-spring
  • mvn clean package

The plugin file (pf4j-spring-demo-plugin1-0.6.0-SNAPSHOT.zip) is available at demo/plugins/plugin1/target.

image.

decebals avatar Feb 20 '19 17:02 decebals

I am trying to build app and plugin separately but I can't. for demo separately its ok to build in one short. Since the implementation of plugin architecture, plugin development should be outsourced.

[ERROR] Failed to execute goal on project pf4j-spring-demo-api: Could not resolve dependencies for project org.pf4j.demo:pf4j-spring-demo-api:jar:0.6.0-SNAPSHOT: Failure to find org.pf4j:pf4j-spring:jar:0.6.0-SNAPSHOT in https://oss.sonatype.org/content/repositories/snapshots was cached in the local repository, resolution will not be reattempted until the update interval of sonatype-nexus-snapshots has elapsed or updates are forced -> [Help 1]

MohankumarD avatar Mar 01 '19 17:03 MohankumarD

@MohankumarD Did you follow the steps described by me in https://github.com/pf4j/pf4j-spring/issues/28#issuecomment-465682047? Is it OK for you and you can run the demo?

decebals avatar Mar 01 '19 17:03 decebals

Yes, I can. But I am not build plugin project alone. I want to build APP and PLUGIN seprately and deploy plugin as JAR file.

MohankumarD avatar Mar 02 '19 09:03 MohankumarD

Now, I think that I understood what you say. You need some resources (pf4j-spring, api) to build a plugin separately so:

  • go to root of pf4j-spring project and run mvn clean install
  • go to pf4j-spring/demo/plugins/plugin1 and run mvn clean package

decebals avatar Mar 02 '19 13:03 decebals

Now, I have added a new dependency in Plugin2. Yes, a ZIP file is working, but still, like a JAR file, I am getting same issue (I am not able to pack plugin as a JAR for deployment).

MohankumarD avatar Mar 04 '19 14:03 MohankumarD

I am not able to pack plugin as a JAR for deployment

For a demo with plugins in format JAR please see PF4J demo.

decebals avatar Mar 05 '19 18:03 decebals