Replying to my own thread... Forgot to attach the stacktrace
May 16, 2009 8:57:35 AM com.sun.jersey.api.core.PackagesResourceConfig init
INFO: Scanning for root resource and provider classes in the packages:
com.asherwin.server
May 16, 2009 8:57:36 AM
com.sun.jersey.server.impl.application.WebApplicationImpl
processRootResources
SEVERE: The ResourceConfig instance does not contain any root resource classes.
May 16, 2009 8:57:36 AM com.sun.grizzly.http.servlet.ServletAdapter service
SEVERE: service exception:
com.sun.jersey.api.container.ContainerException: The ResourceConfig
instance does not contain any root resource classes.
at com.sun.jersey.server.impl.application.WebApplicationImpl.processRootResources(WebApplicationImpl.java:718)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:590)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:383)
at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:377)
at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:242)
at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:449)
at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:169)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:281)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:442)
at javax.servlet.GenericServlet.init(GenericServlet.java:241)
at com.sun.grizzly.http.servlet.ServletAdapter.loadServlet(ServletAdapter.java:374)
at com.sun.grizzly.http.servlet.ServletAdapter.service(ServletAdapter.java:312)
at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:165)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:746)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:655)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:905)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:161)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:136)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:103)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:89)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
at java.lang.Thread.run(Thread.java:613)
On Sat, May 16, 2009 at 8:21 AM, Alex Sherwin <alex.sherwin_at_gmail.com> wrote:
> I've got:
>
> jersey bundle 1.0.3
> grizzly-servlet-webserver 1.9.15a
>
> (also, activation, commons lang, commons logging, jaxb api, jaxb impl,
> jsr311 api)
>
> If I follow the straight forward approach from the HelloWorld example,
> everything works fine when running inside Eclipse (JDK 1.5.0_16).
> However, once i export a jar and run it from a command line (either on
> OS X JDK 1.5.0_16 or OpenSolaris JDK 1.6.0_06) the Grizzly web server
> starts up, but once I make a web request and Jersey attempts to
> initialize, it is failing to locate my HelloWorldResource class
> (again, this works when run from inside Eclipse).
>
> Everything (meaning both of my classes) are in jar, classpath is all
> setup, etc etc...
>
> There is no special run configuration setup in eclipse, just a basic
> Run As > Java Application invocation, which is simply running my main
> method with the classpath setup with my libs.
>
> What could possibly be different between running from within Eclipse
> and the command line that would only change the way that Jersey is
> attempting/failing to locate my resource classes? Here are my two
> test classes...
>
> Note that I've tried configuring the grizzly web server two different
> ways labeled with "Method 1" and "Method 2", both work from within
> Eclipse, both fail the same way when run from the command line
> (Grizzly starts up, but Jersey fails to find Resource classes when a
> web request is made)
>
> After generating my jar (jersey-grizzly.jar), it is run like this:
>
> java -cp .:activation-1.1.1.jar:asm-3.1.jar:commons-lang-2.4.jar:commons-logging-1.1.1.jar:grizzly-servlet-webserver-1.9.15a.jar:jaxb-api-2.1.jar:jaxb-impl-2.1.11.jar:jersey-bundle-1.0.3.jar:jersey-grizzly.jar:jsr311-api-1.0.jar:junit-4.6.jar:log4j-1.2.15.jar
> com.asherwin.server.GrizzlyServer
>
> com.asherwin.server.GrizzlyServer.java
> ==============================
>
> package com.asherwin.server;
>
> import java.io.IOException;
> import java.util.concurrent.TimeUnit;
>
> import org.apache.log4j.Logger;
>
> import com.sun.grizzly.http.StatsThreadPool;
> import com.sun.grizzly.http.embed.GrizzlyWebServer;
> import com.sun.grizzly.http.servlet.ServletAdapter;
> import com.sun.jersey.api.core.PackagesResourceConfig;
>
> public class GrizzlyServer {
>
> private static final Logger LOG = Logger.getLogger(GrizzlyServer.class);
>
> private static final String HOST = "localhost";
> private static final int PORT = 8080;
>
> private static final MyStatistics threadPool = new MyStatistics(10,
> 100, Integer.MAX_VALUE, 60, TimeUnit.SECONDS);
>
> public GrizzlyServer() {
>
> }
>
> public static void main(final String[] args) {
>
> final String baseUri = new
> StringBuilder().append("http://").append(HOST).append(":").append(PORT).append("/").toString();
>
> LOG.info("Starting Grizzly [" + baseUri + "]");
>
> try {
>
> // Method 1
> // final Map<String, String> initParams = new HashMap<String, String>();
> // initParams.put(PackagesResourceConfig.PROPERTY_PACKAGES,
> "com.asherwin.resource");
> // final SelectorThread threadSelector =
> GrizzlyWebContainerFactory.create(baseUri, initParams);
> // threadSelector.setSelectorReadThreadsCount(5);
> // threadSelector.setThreadPool(threadPool);
> // threadSelector.enableMonitoring();
>
> // Method 2
> GrizzlyWebServer ws = new GrizzlyWebServer(PORT);
> ServletAdapter jerseyAdapter = new ServletAdapter();
> jerseyAdapter.setServletInstance(new
> com.sun.jersey.spi.container.servlet.ServletContainer());
> jerseyAdapter.addInitParameter(PackagesResourceConfig.PROPERTY_PACKAGES,
> "com.asherwin.resource");
> ws.addGrizzlyAdapter(jerseyAdapter, new String[] { "/" });
> ws.getSelectorThread().enableMonitoring();
> ws.getSelectorThread().setThreadPool(threadPool);
> ws.start();
>
> // System.in.read();
>
> boolean done = false;
> while (!done) {
>
> // LOG.debug("activeCount [" + threadPool.getActiveCount() +
> "], poolSize [" + threadPool.getPoolSize() + //
> // "], largestPoolSize [" // + threadPool.getLargestPoolSize()
> + "], taskCount [" + threadPool.getTaskCount() +
> // "], completedTaskCount [" // +
> threadPool.getCompletedTaskCount() + "]");
>
> LOG.debug(threadPool.getStats());
>
> Thread.sleep(2000);
> }
>
> // Method 2
> ws.stop();
>
> // Method 1
> // threadSelector.stopEndpoint();
> } catch (IOException e) {
> LOG.error("Caught IOException [" + e.getMessage() + "]", e);
> } catch (InterruptedException e) {
> LOG.error("Caught InterruptedException [" + e.getMessage() + "]", e);
> }
>
> System.exit(0);
>
> }
>
> public static class MyStatistics extends StatsThreadPool {
>
> public MyStatistics(int corePoolSize, int maximumPoolSize, int
> maxTasksCount, long keepAliveTime, TimeUnit unit) {
> super(corePoolSize, maximumPoolSize, maxTasksCount, keepAliveTime, unit);
> }
>
> public String getStats() {
> final StringBuilder sb = new StringBuilder();
>
> sb.append("[Queued = ");
> sb.append(getStatistic().getCountQueued());
>
> sb.append(", Total Queued = ");
> sb.append(getStatistic().getCountTotalQueued());
>
> sb.append(", Peak Queued = ");
> sb.append(getStatistic().getPeakQueued());
>
> sb.append(", Open Connections = ");
> sb.append(getStatistic().getOpenConnectionsCount());
>
> sb.append(", Total Connections = ");
> sb.append(getStatistic().getCountTotalConnections());
>
> sb.append(", Max Queued = ");
> sb.append(getStatistic().getMaxQueued());
>
> sb.append(", Queue Size Bytes = ");
> sb.append(getStatistic().getQueueSizeInBytes());
>
> sb.append("]");
> return sb.toString();
> }
> }
> }
>
>
> com.asherwin.resource.HelloWorldResource.class
> =======================================
>
> package com.asherwin.resource;
>
> import javax.ws.rs.GET;
> import javax.ws.rs.Path;
> import javax.ws.rs.core.Response;
>
> @Path("/helloworld")
> public class HelloWorldResource {
>
> public HelloWorldResource() {
>
> }
>
> @GET
> public Response helloWorld() {
> return Response.ok("Hello World").build();
> }
>
> }
>
>
> --
> Alexander Sherwin
>
--
Alexander Sherwin