• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

NetBeans Module

 
Ranch Hand
Posts: 248
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Source:
http://docs.oracle.com/netbeans/nb82/netbeans/NBDAG/nbeans_modules.htm
5.10.1 About Service Providers
The second paragraph.

The basic idea is that each JAR file (in NetBeans terminology, each module) that wishes to provide an implementation of some interface,for example javax.xml.parsers.DocumentBuilderFactory, can create its own implementation of the interface, say org.sakson.MyFactory, and expose it to the system as a service by creating a META-INF/services/javax.xml.parsers.DocumentBuilderFactory file inside of its own JAR file.


I will be super grateful if someone can explain what the paragraph is saying.
a)  The document makes several references to the word "system". I am just wondering what system it is talking about.

b) The META-INF/services.  Where does this reside?
 
Saloon Keeper
Posts: 10539
224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
'System' refers to the rest of the runtime. Services that were loaded this way can be used by all other code running in the same JVM instance.

META-INF/services must be literally where the text you quoted says it must be: in the root folder of the JAR that provides the service, there must be a folder named META-INF containing a folder named services, which contains a file for each service provider interface (SPI) that you want to implement. One such file must be named using the fully qualified type name of the SPI you want to implement, and its contents must consist of the fully qualified type names of all the classes that your module provides that implement the SPI.

You can easily add these files to your JAR by adding a META-INF/services folder to one of the source directories of your module. This is like creating a package named META-INF with a subpackage META-INF.services.

Note that all of this isn't specific to NetBeans. You can create a plugin system for your own applications as well using the ServiceLoader class. Its documentation should provide you more detailed information about Java's service loading mechanism.
 
Biniman Idugboe
Ranch Hand
Posts: 248
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan, when I am eventually able to write a working application in Java, I will always remember your contributions and those of others as well.  So now:

One such file must be named using the fully qualified type name of the SPI you want to implement, and its contents must consist of the fully qualified type names of all the classes that your module provides that implement the SPI.


What type of file would this be - plain text, xml or something else?
 
Stephan van Hulst
Saloon Keeper
Posts: 10539
224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad to help.

Plain text, one class name per line, but usually you only need one class per SPI. I don't remember if it's necessary to terminate the last class name with a line ending, but it's good practice to do so (so that there's a single blank line at the end of the file).

The file name must have no extension like .txt or anything. Just the fully qualified name of the SPI.
 
Biniman Idugboe
Ranch Hand
Posts: 248
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

'System' refers to the rest of the runtime.


I am not quite sure I understand the meaning of "the rest of the runtime".  I am just thinking, maybe a module is its own system in its own right.
 
Stephan van Hulst
Saloon Keeper
Posts: 10539
224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. In this context, 'system' refers to the JVM instance + all loaded modules. Services that your module provides are available to the NetBeans platform and all other loaded modules.
 
Biniman Idugboe
Ranch Hand
Posts: 248
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again.  One more area that needs clarification.  The plain text file!  How does one create  a plain text file in NetBeans IDE?  I am learning to use NetBeans 11.1.
 
Stephan van Hulst
Saloon Keeper
Posts: 10539
224
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right click the META-INF.services package in your project explorer and select "New -> Other...". Under "Categories", select "Other" and then under "File Types" select "Empty File".
 
Biniman Idugboe
Ranch Hand
Posts: 248
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Respect, that's what I have for you!
 
You can thank my dental hygienist for my untimely aliveness. So tiny:
professionally read, modify and write PDF files from Java
https://products.aspose.com/pdf/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!