Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6374777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:31:49+00:00 2026-05-25T01:31:49+00:00

I am using Maven with Eclipse (using M2E) to build a project that relies

  • 0

I am using Maven with Eclipse (using M2E) to build a project that relies on java.util.ServiceLoader to dynamically load some factory classes. It works fine when I run it in Maven, but when I run a test using the inbuilt Eclipse JUnit4 Runner, it fails to pick up the services and the tests do not succeed.

Is there something I need to do to manually add the META-INF/services to the JUnit build path? I couldn’t make it work in either src/main/resources/META-INF/services or src/main/java/META-INF/services. Is it related to the way M2E sets up the build path? I made up the test in a completely new project and it still failed.

The basic code that is failing is:

public class TestServiceLoader<S>
{
   public TestServiceLoader(final Class<S> serviceClass)
   {

       ServiceLoader<S> serviceLoader =
            java.util.ServiceLoader.load(serviceClass, serviceClass.getClassLoader());

       Iterator<S> services = serviceLoader.iterator();

       if(!services.hasNext())
       {
           throw new RuntimeException("Failed to get any services for this class");
       }
   }
}

The test looks like:

@Test
public final void testTestServiceLoader()
{
    TestServiceLoader<TestFactory> serviceLoader = new TestServiceLoader<TestFactory>(TestFactory.class);
}

TestFactory is defined as:

public interface TestFactory
{

}

TestFactoryImpl is defined as:

public class TestFactoryImpl implements TestFactory
{

}

I originally was using the MetaInfServices generator from http://weblogs.java.net/blog/kohsuke/archive/2009/03/my_project_of_t.html but when I removed that and manually created the files by hand, it was still failing in the same way for Eclipse while succeeding when run using the Maven Surefire plugin.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:31:50+00:00Added an answer on May 25, 2026 at 1:31 am

    The M2E developers appear to believe that any resources will affect a maven build, even in the case where META-INF/services/ is a functional part, albeit a resource:

    “Actually project resource folder doesn’t really need to be added to the buildpath (Maven Builder is going to work without it), but it been considered convenient and look better in the Package Explorer and other Eclipse views.”
    M2E FAQ

    If you want to hack around it, you can apparently encode a special M2E profile into your pom.xml files to make the M2E incremental build filter and copy resources Sonatype M2Eclipse Wiki

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a Java/Flex project that I'm building using Maven. After doing some research
Is it possible to export my maven Java project on Eclipse to users that
I packaging my java project with maven, using the M2 Plug in Eclipse I
I'm trying to migrate an existing eclipse web project (wtp) to maven, using m2e.
I am considering using Maven for a Java open source project I manage. In
I've got a project using Maven 2 as the build tool. Now I am
I have a small command line utility project that I'm using Maven to manage.
I am using Maven in Eclipse to manage the project dependencies which are resolved
I have a multi module Spring project that I set up using Maven: my-root
How to create new Eclipse RCP project using Maven ( preferably m2eclipse )? I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.