I'm trying to learn the ins and outs of using Eclipse to set up a web service. I've started with this tutorial. I was able to get something to work, but I'm finding that if I make simple changes to the Java code and try to rerun it, I can't get the changed version to run.
My class looks like this (imports suppressed):
package com.mypackage.mytest;
@Path("/helloworld")
public class HelloWorld {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayPlainTextHello() {
return "Hello World #1";
}
@GET
@Produces(MediaType.TEXT_XML)
public String sayXMLHello() {
return "<?xml version=\"1.0\"?>" + "<hello> Hello World #2 RESTful Jersey"
+ "</hello>";
}
@GET
@Produces(MediaType.TEXT_HTML)
public String sayHtmlHello() {
return "<html> " + "<title>" + "Hello World RESTful #3 Jersey"
+ "</title>" + "<body><h1>" + "Hello World #3 RESTful Jersey"
+ "</body></h1>" + "</html> ";
}
}
web.xml looks like:
<?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" version="3.0">
<display-name>TestService</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>TestService</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.mypackage.mytest</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>TestService</servlet-name>
<url-pattern>/hello/*</url-pattern>
</servlet-mapping>
</web-app>
I've set it up to use Tomcat 7.0, Servlet version 3.0. I'm running it by selecting "Run As -> Run On Server" on the project name.
If I bring up http://localhost:8080/TestService/hello/helloworld, it displays one of the above outputs.
However, if I change the string constants in the above Java code (e.g. changing #1 to #4, #2 to #5, #3 to #6), and attempt to rerun it, it still displays one of the old strings--the changes don't seem to take. I've tried different combinations of stopping the server, Build Project, and things that say "Publish", but so far the only things I've found that cause changes to appear are Project->Clean and restarting Eclipse. It doesn't make sense that I should have to clean my whole project to get changes to deploy, so I must be missing some other basic step ... but what?