• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

francisdb/serviceloader-maven-plugin: Maven plugin for generating java servicelo ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

francisdb/serviceloader-maven-plugin

开源软件地址(OpenSource Url):

https://github.com/francisdb/serviceloader-maven-plugin

开源编程语言(OpenSource Language):

Java 100.0%

开源软件介绍(OpenSource Introduction):

Build status Maven Central

This maven plugin generates services files for the ServiceLoader introduced in Java 6 : https://docs.oracle.com/javase/9/docs/api/java/util/ServiceLoader.html

Use

for example:

<build>
  <plugins>
    <plugin>
      <groupId>eu.somatik.serviceloader-maven-plugin</groupId>
      <artifactId>serviceloader-maven-plugin</artifactId>
      <version>1.3.1</version>
      <configuration>
        <services>
          <param>com.foo.Dictionary</param>
          <param>com.foo.Operation</param>
        </services>
      </configuration>
      <executions>
        <execution>
          <goals>
            <goal>generate</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

this will generate these files:

  • META-INF/services/com.foo.Dictionary
  • META-INF/services/com.foo.Operation

by scanning the generated classes and finding all non-abstract/non-interface implementations of the service interfaces. The plugin itself has no Java 6 dependency

Excludes / includes

Additionally it is possible to filter implementation classes via includes and excludes section in the configuration. The class name notation is the same as for the services section.

for example:

<build>
  <plugins>
    <plugin>
      <groupId>eu.somatik.serviceloader-maven-plugin</groupId>
      <artifactId>serviceloader-maven-plugin</artifactId>
      <version>1.3.1</version>
      <configuration>
        <services>
          <param>com.foo.Dictionary</param>
          <param>com.foo.Operation</param>
        </services>
        <includes>
          <include>*.RightClass*</include>
        </includes>
      </configuration>
      <executions>
        <execution>
          <goals>
            <goal>generate</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

This should add only implementation classes that begin with RightClass*.

Missing Service Classes

The default action when a service class is missing is to fail the build. If you want to ignore this service, you can use the failOnMissingServiceClass option (true by default).

for example:

<build>
  <plugins>
    <plugin>
      <groupId>eu.somatik.serviceloader-maven-plugin</groupId>
      <artifactId>serviceloader-maven-plugin</artifactId>
      <version>1.3.1</version>
      <configuration>
      	<failOnMissingServiceClass>false</failOnMissingServiceClass>
        <services>
          <param>com.foo.MissingService</param>
        </services>
      </configuration>
      <executions>
        <execution>
          <goals>
            <goal>generate</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

Example

A example project is provided and can be run like this:

$ mvn clean install
...
[INFO] Generating service file .../example/target/classes/META-INF/services/eu.somatik.serviceloader.Operation
[INFO]   + eu.somatik.serviceloader.SimpleOperation
...

$ java -jar target/example-1.0-SNAPSHOT.jar
Found service implementation: eu.somatik.serviceloader.SimpleOperation@579a19fd
Hello world

Release

see http://central.sonatype.org/pages/apache-maven.html#performing-a-release-deployment-with-the-maven-release-plugin

Note: do export GPG_TTY=$(tty) first if you have gpg: signing failed: Inappropriate ioctl for device errors

mvn -P release release:clean release:prepare
mvn -P release release:perform



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
julianrios/Maven.Spring-EmployeeDirectory发布时间:2022-08-17
下一篇:
ZipCodeCore/ItemSorter.maven发布时间:2022-08-17
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap