Last active
September 24, 2017 02:48
-
-
Save theotherian/6181277 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There are two dependencies that Jersey 2.0 has for adapting its application to a Servlet instance. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- use the following artifactId if you don't need servlet 2.x compatibility --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.ws.rs.GET; | |
import javax.ws.rs.Path; | |
import javax.ws.rs.Produces; | |
import javax.ws.rs.core.MediaType; | |
import javax.ws.rs.core.Response; | |
@Path("hello") | |
public class HelloResource { | |
@GET | |
@Produces(MediaType.TEXT_PLAIN) | |
public Response get() { | |
return Response.ok("hello").build(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- use the following artifactId for servlet 3.x configuration features that don't require web.xml --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- This supports Servlet 2.x --> | |
<dependency> | |
<groupId>org.glassfish.jersey.containers</groupId> | |
<artifactId>jersey-container-servlet-core</artifactId> | |
<version>2.1</version> | |
</dependency> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- This does NOT support Servlet 2.x --> | |
<!-- (but it does support Servlet 3.0's web.xml-less configuration) --> | |
<dependency> | |
<groupId>org.glassfish.jersey.containers</groupId> | |
<artifactId>jersey-container-servlet</artifactId> | |
<version>2.1</version> | |
</dependency> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.ws.rs.ApplicationPath; | |
import org.glassfish.jersey.server.ResourceConfig; | |
@ApplicationPath("myapp") | |
public class JerseyApp extends ResourceConfig { | |
public JerseyApp() { | |
register(HelloResource.class); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>com.theotherian</groupId> | |
<artifactId>jersey-example</artifactId> | |
<version>1.0-SNAPSHOT</version> | |
<packaging>war</packaging> | |
<name>jersey-example</name> | |
<build> | |
<finalName>jersey-example</finalName> | |
<plugins> | |
<plugin> | |
<artifactId>maven-compiler-plugin</artifactId> | |
<configuration> | |
<source>1.7</source> | |
<target>1.7</target> | |
</configuration> | |
</plugin> | |
<plugin> | |
<artifactId>maven-war-plugin</artifactId> | |
<configuration> | |
<failOnMissingWebXml>false</failOnMissingWebXml> | |
</configuration> | |
</plugin> | |
</plugins> | |
</build> | |
<dependencies> | |
<dependency> | |
<groupId>org.glassfish.jersey.containers</groupId> | |
<!-- uncomment this line and comment out jersey-container-servlet to see this break --> | |
<!-- <artifactId>jersey-container-servlet-core</artifactId> --> | |
<artifactId>jersey-container-servlet</artifactId> | |
<version>2.1</version> | |
</dependency> | |
</dependencies> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you, thank you, THANK YOU!
I spent 3hrs trying to get Servlet 3.x + Jersey 2.x to play nice together. Nothing but 404s, until I found your blog post (http://www.theotherian.com/2013/08/jersey-2.0-servlet-3.0-problems-applicationpath.html) on jersey-container-servlet-core vs jersey-container-servlet.