I am trying to do the following tutorial in IntelliJ on OSX:
http://www.vogella.com/tutorials/REST/article.html
When running the code in Eclipse, everything works fine. But running code in IntelliJ delivers 404s for the same URI.
The program should run on Apache Tomcat Server 8.0.20.
I did what was written in the tutorial, but I can’t understand why it will not work in IntelliJ. I searched for a few days and found a solution.
It seems that something with the deployment is wrong, because index.jsp is working fine.
Hope someone can help me.
Program code:
Hello class:
package com.vogella.jersey.first;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/hello")
public class Hello {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayPlainTextHello() {
return "Hello Jersey";
}
@GET
@Produces(MediaType.TEXT_XML)
public String sayXMLHello() {
return "<?xml version=\"1.0\"?>" + "<hello> Hello Jersey" + "</hello>";
}
@GET
@Produces(MediaType.TEXT_HTML)
public String sayHtmlHello() {
return "<html> " + "<title>" + "Hello Jersey" + "</title>"
+ "<body><h1>" + "Hello Jersey" + "</body></h1>" + "</html> ";
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>com.vogella.jersey.first</display-name>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.vogella.jersey.first</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
Project structure: (Unable to post photos due to low reputation, Sorry I'm new)
- Rest
- .idea
- Lib
- javax.ws.rs-api-2.0.jar
- jersey-client.jar
- -common.jar
- --servlet.jar
- ---core.jar
- -server.jar
- rest.iml