Closed free-leung closed 1 year ago
Additional version information: JDK 11 pf4j-spring 0.8.0
Ok, I found out why.
The plugins
module packaging error. I introduced the corresponding packaging plug-in into the plugins module and the problem was solved.
Problematic pom file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.tigers.gateway</groupId>
<artifactId>edge-gateway</artifactId>
<version>1.0-Alpha</version>
</parent>
<artifactId>plugins</artifactId>
<packaging>pom</packaging>
<modules>
<module>hello-plugin</module>
</modules>
<dependencies>
....... Elliptic dependence
</dependencies>
<properties>
<!-- Override below properties in each plugin's pom.xml -->
<plugin.id />
<plugin.class />
<plugin.version />
<plugin.provider />
<plugin.dependencies />
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>${project.artifactId}-${project.version}</finalName>
<appendAssemblyId>false</appendAssemblyId>
<attach>false</attach>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
<manifestEntries>
<Plugin-Id>${plugin.id}</Plugin-Id>
<Plugin-Version>${plugin.version}</Plugin-Version>
<Plugin-Provider>${plugin.provider}</Plugin-Provider>
<Plugin-Class>${plugin.class}</Plugin-Class>
<Plugin-Dependencies>${plugin.dependencies}</Plugin-Dependencies>
</manifestEntries>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Then I replace the corresponding plug-in:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Plugin-Id>${plugin.id}</Plugin-Id>
<Plugin-Version>${plugin.version}</Plugin-Version>
<Plugin-Provider>${plugin.provider}</Plugin-Provider>
<Plugin-Class>${plugin.class}</Plugin-Class>
<Plugin-Dependencies>${plugin.dependencies}</Plugin-Dependencies>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
The code working now~
Hello here. I wrote an sdk package to specify the extension interface.
Then create plugins in the plugins module and implement the extensions in the sdk. code like:
The project started just as I had hoped, and the plug-in and corresponding extensions were loaded. The logger print:
But I wonder, why did I pass Greeting.class to visit GreetingService got a null. The code like:
This code yields a list of 0. Then I look at the extension inside by the plug-in id:
Logger say:
I see in the example that the implementation can be accessed through the interface. Why isn't my code working?