Grizzly and jersey

I am trying to put Grizzly with Jersey as a single jar using the Maven shade plugin. But I always get the message No container provider supports the type class org.glassfish.grizzly.http.server.HttpHandler

The code works fine in Eclipse, but not in a packaged jar:

 public class Main { private static URI getBaseURI() { return UriBuilder.fromUri("http://localhost/").port(9998).build(); } public static final URI BASE_URI = getBaseURI(); protected static HttpServer startServer() throws IOException { System.out.println("Starting grizzly..."); ResourceConfig rc = new PackagesResourceConfig("share.test"); rc.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); return GrizzlyServerFactory.createHttpServer(BASE_URI, rc); } public static void main(String[] args) throws IOException { HttpServer httpServer = startServer(); System.in.read(); httpServer.stop(); } } 

Here is the complete exception

 $ java -jar target/webServiceTest-0.0.1-SNAPSHOT.jar Starting grizzly... Mar 20, 2012 12:48:53 PM com.sun.jersey.api.core.PackagesResourceConfig init INFO: Scanning for root resource and provider classes in the packages: share.test Mar 20, 2012 12:48:54 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses INFO: Root resource classes found: class share.test.NonJAXBBeanResource class share.test.Hello Mar 20, 2012 12:48:54 PM com.sun.jersey.api.core.ScanningResourceConfig init INFO: No provider classes found. Exception in thread "main" java.lang.IllegalArgumentException: No container provider supports the type class org.glassfish.grizzly.http.server.HttpHandler at com.sun.jersey.api.container.ContainerFactory.createContainer(ContainerFactory.java:196) at com.sun.jersey.api.container.ContainerFactory.createContainer(ContainerFactory.java:134) at com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory.createHttpServer(GrizzlyServerFactory.java:242) at share.test.Main.startServer(Main.java:27) at share.test.Main.main(Main.java:31) 

I am creating a jar package using maven with

 <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>1.5</version> <configuration> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <manifestEntries> <Main-Class>share.test.Main</Main-Class> <Build-Number>1</Build-Number> </manifestEntries> </transformer> </transformers> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> </execution> </executions> </plugin> </plugins> </build> 

Do I need to change the shadow plugin to include anything else?

+8
java maven jersey grizzly
source share
3 answers

The error is similar to the fact that the plugin does not merge META-INF / services records from different banks correctly - if several files with the same name contain several files in the META-INF / services directory, they must be combined, they are not replaced by each other. Check if this is so.

+8
source share

The following links helped me figure out the solution below:

especially the answer

  • https://stackoverflow.com/questions/390283/ ...

Instead of using jar-with-dependencies as the Ref descriptor of your plug-in assembly configuration, you create our own, for example. in src / assembly / depmerge.xml (see below). This build configuration will add a containerDescriptorHandler that will serve META-INF / services.

to run

 mvn clean compile assembly:single 

to get the jar file into the target, which you can call with

 java -jar target/xy-version-jar-with-dependencies.jar 

pom.xml:

  <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>2.5.3</version> <configuration> <archive> <manifest> <mainClass>${mainClass}</mainClass> </manifest> </archive> <descriptor>src/assembly/depmerge.xml</descriptor> </configuration> </plugin> 

Src / builds / depmerge.xml:

 <!-- see http://maven.apache.org/guides/mini/guide-assemblies.html see http://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html --> <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> <!-- TODO: a jarjar format would be better --> <id>jar-with-dependencies-and-services</id> <formats> <format>jar</format> </formats> <includeBaseDirectory>false</includeBaseDirectory> <dependencySets> <dependencySet> <outputDirectory>/</outputDirectory> <useProjectArtifact>true</useProjectArtifact> <unpack>true</unpack> <scope>runtime</scope> </dependencySet> </dependencySets> <!-- /questions/390283/how-can-i-merge-resource-files-in-a-maven-assembly --> <containerDescriptorHandlers> <containerDescriptorHandler> <handlerName>metaInf-services</handlerName> </containerDescriptorHandler> </containerDescriptorHandlers> </assembly> 
+1
source share

I just made a stupid mistake. Configure maven-assembly-plugin in pom as well.

The assembly seems to replace META-INF / services and override "com.sun.jersey.server.impl.container.grizzly2.GrizzlyContainerProvider" in the com.sun.jersey.spi.container.ContainerProvider file

As indicated by http://maven.apache.org/plugins/maven-assembly-plugin/ , if your project wants to pack your artifact in uber-jar, the build plugin provides only basic support.For more control, use the Maven Shade plugin.

  <!-- mvn assembly:assembly --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <mainClass>XXX.DaemonMain</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> </plugin> 
0
source share

All Articles