Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Dependency in Plugin application #28

Open
MohankumarD opened this issue Feb 14, 2019 · 19 comments
Open

Add Dependency in Plugin application #28

MohankumarD opened this issue Feb 14, 2019 · 19 comments

Comments

@MohankumarD
Copy link

MohankumarD commented Feb 14, 2019

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 #19 (comment)

@decebals
Copy link
Member

decebals commented Feb 14, 2019

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?

@MohankumarD
Copy link
Author

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

@decebals
Copy link
Member

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.

@MohankumarD
Copy link
Author

MohankumarD commented Feb 15, 2019

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

@decebals
Copy link
Member

decebals commented Feb 15, 2019

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.

@sljinlet
Copy link

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
Copy link

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

@MohankumarD
Copy link
Author

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.

@decebals
Copy link
Member

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,

@MohankumarD
Copy link
Author

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”

@decebals
Copy link
Member

@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.

@MohankumarD
Copy link
Author

@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.

@decebals
Copy link
Member

@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.

@MohankumarD
Copy link
Author

MohankumarD commented Mar 1, 2019

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]

@decebals
Copy link
Member

decebals commented Mar 1, 2019

@MohankumarD
Did you follow the steps described by me in #28 (comment)? Is it OK for you and you can run the demo?

@MohankumarD
Copy link
Author

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.

@decebals
Copy link
Member

decebals commented Mar 2, 2019

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

@MohankumarD
Copy link
Author

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).

@decebals
Copy link
Member

decebals commented Mar 5, 2019

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants