简体   繁体   中英

Maven and the java plugin framework

i have a question that is a little difficult to explain but i'll try my best to do so. If you don't understand anything or need more information feel free to ask. :)

I have a java project that uses the java plugin framework. That means i'm searching for projects with a specific structure in the classpath of my project. I have two projects which have this needed structure and are included in the main project pom.xml as dependencies like that:

<dependency>
    <groupId>package</groupId>
    <artifactId>One</artifactId>
    <version>1.0</version>
</dependency>
<dependency>
    <groupId>package</groupId>
    <artifactId>Two</artifactId>
    <version>1.0</version>
</dependency>

I'm retrieving the available classes via the ServiceLoader like that:

loader = ServiceLoader.load(ISomeInterface.class);
loader.iterator();

My problem is, that the ServiceLoader.load call only delivers only the project that is mentioned first in my pom.xml.

Has anyone of you made similiar experiences or can help my with this problem?

Thanks in advance, Loris

I found the problem and resolved it!!! The problem is that each of my plugin contained a file called "META-INF/full.qualified.interface" which had the content "full.qualified.interfaceimplementation". Maven only packaged the file of the first project instead of merging the content of the files for each project. So all you need to do is to configure maven to merge all "META-INF/full.qualified.interface" files it finds using the shade plugin:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.4.1</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <transformers>
                    <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
                </transformers>
            </configuration>
        </execution>
    </executions>
</plugin>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM