5

I am trying to use a set of JAX-RS web resources packaged in a 3rd party jar. In that same jar, there is a set of @Providers which I would like replace with my own.

Is there a way to tell the JAX-RS runtime to skip loading certain classes?

The resources and providers are in the same package.

bruno
  • 2,213
  • 1
  • 19
  • 31
Karthik Ramachandran
  • 11,925
  • 10
  • 45
  • 53

2 Answers2

0

Have you tried using maven exclusions. Similar issue I had and resolved with

    <!-- For Restful Client -->
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-client</artifactId>
        <version>1.8</version>
        <exclusions>
            <exclusion>
                <groupId>com.sun.jersey</groupId>
                <artifactId>resteasy-jaxrs</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

And then you can load your provider classes usig eclipse's classpath

Kisanagaram
  • 289
  • 2
  • 10
  • Thanks, the problem is that the particular provider I would like to exclude is mixed in with some resources in a particular jar. So i need a way to exclude particular files form a jar. – Karthik Ramachandran Jul 10 '13 at 05:25
  • 2
    This is a build time solution that depends on the person building the war to have eclipse. I was hoping for a solution entirely within the JAX-RS framework. – Karthik Ramachandran Jul 20 '13 at 23:51
0

I was able to solve this in JBoss AS 7 by specifying the providers and resources manually in my Application class. By default, when you do not override the getClasses() method, JBoss would automatically scan for every provider and resource. By overriding this method, JBoss disables automatic scanning and I was able to specify every single provider/resource except the 3rd party one I wanted to exclude.

To ease the pain of having to specify every single resource class, I used a library called reflections to dynamically lookup my custom resource classes which I keep all in the same package. Here's my solution:

@ApplicationPath("/")
public class MyApplication extends Application {
  @Override
  public Set<Class<?>> getClasses() {
    final Set<Class<?>> classes = new HashSet<>();
    addResources(classes, "my.package.containing.resources");
    return classes;
  }

  private void addResources(final Set<Class<?>> classes, final String pkg) {
    classes.addAll(new Reflections(pkg, new SubTypesScanner(), new TypeAnnotationsScanner()).getTypesAnnotatedWith(Path.class));
  }
}