• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

ServiceLoader does not load classes provided by config file

 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello
I have the following problem:
I created a ServiceLoader that is supposed to load the classes ImmobilieGespeichert and ImmobilieBerechnet (My project is in german).
The problem is that it does not load anything.
Here is my code:
Interface Immobilie:


Class ImmobilieBerechnet:


Class ImmobilieGespeichert:


Class Main:



Now the List of the ArrayList is 0 when it should be 2 (For the 2 Classes).

My Config File simply contains the following


And it is in the META-INF/services directory.
The file is placed correctly because the JUnit test does not bring an error.

My Junit test is basically the code from Main with "assertEquals" added at end.

What could be wrong here?
Thanks!
 
Sheriff
Posts: 22682
128
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I assume you've named your config file correcly? As in, the file name is exactly the same as the interface name (with no extension)?
 
Dennis Von Valkenburgh
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Spoor wrote:I assume you've named your config file correcly? As in, the file name is exactly the same as the interface name (with no extension)?


The name is:
de.ostfalia.swt.aufgabe2.Immobilie
 
Rob Spoor
Sheriff
Posts: 22682
128
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That looks correct. Can you check if the file is on the class path when running the unit tests? If you're using Maven, that means it should be in src/main/resources/META-INF/services.
 
reply
    Bookmark Topic Watch Topic
  • New Topic