Skip to content

Instantly share code, notes, and snippets.

@lzhoucs
Last active January 14, 2017 08:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lzhoucs/7037961 to your computer and use it in GitHub Desktop.
Save lzhoucs/7037961 to your computer and use it in GitHub Desktop.
jax-rs with jersey 2.3 + tomcat 7
eclipse JEE + tomcat 7 server(embedded in eclipse)
runtime jar required(for tomcat 7):
asm-all-repackaged-2.2.0-b14.jar
cglib-2.2.0-b14.jar
guava-14.0.1.jar
hk2-api-2.2.0-b14.jar
hk2-locator-2.2.0-b14.jar
hk2-utils-2.2.0-b14.jar
javax.annotation-api-1.2.jar
javax.inject-2.2.0-b14.jar
jaxb-api-2.2.7.jar(not sure)
validation-api-1.1.0.Final.jar
jersey-client.jar
jersey-common.jar
jersey-container-servlet-core.jar
jersey-container-servlet.jar
jersey-server.jar
javax.ws.rs-api-2.0.jar
url:
http://host:port/rest/service
this example doesn't include client side code.
<servlet>
<servlet-name>REST Services</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>foo.restful</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>REST Services</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
package foo.restful;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
/**
* A RESTFul Web Service that provides Endeca Workbench(WebStudio)
* Authentication service to internal apps(such as Merchtools) through HTTP.
*
* @author lzhoucs
*
*/
@Path("service")
public class WSAuthService {
/**
*
* @return "true" for success, "false" otherwise
*/
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayPlainTextHello() {
return "Hello Jersey";
}
}
@BioQwer
Copy link

BioQwer commented Jan 14, 2017

Jersey Guide says you can you auto generation for create application with support jersey.

mvn archetype:generate -DarchetypeArtifactId=jersey-quickstart-webapp \
                -DarchetypeGroupId=org.glassfish.jersey.archetypes -DinteractiveMode=false \
                -DgroupId=com.example -DartifactId=simple-service-webapp -Dpackage=com.example \
                -DarchetypeVersion=2.25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment