0
votes

I developing a Jersey based application and using Grizzly to test the application. As long as I run it from Eclipse everything works well! However, when I do an export to a runnable Jar and execute at the Windows 7 command prompt I am consistently getting the error message below: My main method is listed, what am I missing. (Thanks for the help)

private static final String PORT="8899";
private static final String MACHINE="http://localhost";
private static final String MAIN_PACKAGE="aklero.idea.persistence";
private static final String JERSEY_PACKAGE="com.sun.jersey.config.property.packages";
private static final String MACHINE_URI=MACHINE+":"+PORT+"/";

public static void main(String[] args) throws IOException
{
    final String baseUri = MACHINE_URI;
    final Map<String, String> initParams = new HashMap<String, String>();      
    initParams.put(JERSEY_PACKAGE, MAIN_PACKAGE);
    System.out.println("Starting grizzly...");
    SelectorThread threadSelector = GrizzlyWebContainerFactory.create(baseUri, initParams);
    System.in.read();
    threadSelector.stopEndpoint();
    System.exit(0);         
}

The errors I am getting:

SEVERE: The ResourceConfig instance does not contain any root resource classes.

Apr 28, 2011 12:42:56 PM com.sun.grizzly.http.servlet.ServletAdapter doService

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.RootResourceUriRules.

(RootResourceUriRules.java:103)

2
I have exactly the same problem and wonder if you have already found a solution besides the manual creation of the runnable JAR?Philipp T.

2 Answers

0
votes
0
votes

I had the same problem. The solution is adding the resource files manually.

Change your 2 variables:

private static final String MAIN_PACKAGE = "yourpackage2.MyApplication";
private static final String JERSEY_PACKAGE = "javax.ws.rs.Application";

and create this file:

package yourpackage2;

import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.core.Application;

public class MyApplication extends Application {
    public Set<Class<?>> getClasses() {
        Set<Class<?>> s = new HashSet<Class<?>>();
        s.add(yourpackage1.ResourceClass1.class);
        //s.add(...); and so on
        return s;
    }
}

When creating your jar within eclipse activate the radio button "Package required libraries into generated JAR"

If there are other jars you use, include them into your classpath when starting your program. Simply with: java -cp ./DIR1;./DIR2;./DIR3 -jar myJAR.jar