What is the ideal way to configure Tomcat to serve directly from my project\'s directory inside of my workspace? (related)
I want my static web resources
Use grizzly webserver. It's completely implemented in java, hence you have full plattform independency and you can start it directly from your workspace without configuring any external programs.
It's easy to deploy resources statically. You just have to derive javax.ws.rs.core.Application
and add your resources as in the example.
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.core.Application;
/**
* Application class that contains resources for the RESTful web service.
*
*/
public class MyApplication extends Application {
public Set> getClasses() {
Set> s = new HashSet>();
s.add(com.rest.test.SomeClass.class);
return s;
}
}
This is needed to configure the servlet adapter. It's also possible to add resources dynamically. But I can't tell you how fast the updating of the resources is with the dynamic approach. Anyway there is enough documentation available online.
private static GrizzlyWebServer getServer(int port,
String webResourcesPath, String contextPath) {
GrizzlyWebServer gws = new GrizzlyWebServer(port, webResourcesPath);
ServletAdapter sa = new ServletAdapter();
/* here they are added statically */
sa.addInitParameter("javax.ws.rs.Application", "com.rest.MyApplication");
sa.setContextPath(contextPath);
sa.setServletInstance(new ServletContainer());
sa.setProperty("load-on-startup", 1);
gws.addGrizzlyAdapter(sa, new String[] { contextPath });
return gws;
}