Note that there are some explanatory texts on larger screens.

plurals
  1. POJersey can't find resources when deployed as JAR, but works in Eclipse
    primarykey
    data
    text
    <p>I'm embedding a Grizzly server within a java stand-alone app. I'm using Jersey to serve some resources using REST calls. While this works perfectly when I'm running/debugging in Eclipse, when trying to create a JAR using Export -> Runnable JAR, I get the following error all the time:</p> <p><strong>SEVERE: The ResourceConfig instance does not contain any root resource classes.</strong></p> <p>Here is my class that starts the Grizzly Server:</p> <pre><code>/** * Constructor */ public RestServer(){ //set up default initParams initParams.put( "com.sun.jersey.config.property.packages", packageName); initParams.put( "com.sun.jersey.api.json.POJOMappingFeature", Boolean.toString(jsonParsing)); } /** * Starts the Grizzly Server thread * @return TRUE if start was correct */ public boolean startGrizzly(){ if (grizzlyRunning){ Logger.error(DEBUG_TAG, "Grizzly Server is already running"); return false; } else{ String hostString = host; String portString = Integer.toString(port); String server = "http://" + hostString + ":" + portString + "/"; try { selector = GrizzlyWebContainerFactory.create( server, initParams ); selector.setKeepAliveTimeoutInSeconds(-1); grizzlyRunning = true; return true; } catch (IllegalArgumentException | IOException e) { Logger.error(DEBUG_TAG, "There was an error trying to start the Grizzly Server. Reason is " + e.getMessage()); grizzlyRunning = false; return false; } } } /** * Stops the Grizzly Server thread * @return TRUE if stop was correct */ public boolean stopGrizzly(){ if (grizzlyRunning){ selector.stopEndpoint(); grizzlyRunning = false; return true; } else{ Logger.error(DEBUG_TAG, "Grizzly is not running. Cannot stop it"); return false; } } </code></pre> <p>Package name contains the path to my other class that has the REST resources, in this case "com.mareculum.model". That said, this is the class that serves:</p> <pre><code>package com.mareculum.model; @Path("/json") public class RestResources { /** * Debugging tag */ private static final String DEBUG_TAG = "RestResources"; /** * Gets the JSON collection of data from itsaseusbuoys * @return The JSON array containing the data from itsaseus buoys */ @GET @Path("/get/itsaseus_data_raw") @Produces(MediaType.APPLICATION_JSON) public ItsaseusDataEntity [] getItsaseusDataRaw() { Vector&lt;ItsaseusDataEntity&gt; ret = getItsaseusBuoysData(); if (ret != null){ return (ItsaseusDataEntity[]) ret.toArray(); } else{ return null; } } /** * Gets the JSON collection of data from itsaseusbuoys * @return The JSON array containing the data from itsaseus buoys */ @GET @Path("/get/itsaseus_fusion_table") @Produces(MediaType.APPLICATION_JSON) public ItsaseusFusionTableRow [] getItsaseusDataEntity() { ArrayList&lt;ItsaseusFusionTableRow&gt; data = getDataFromItsaseusTable(); ItsaseusFusionTableRow [] retArray = new ItsaseusFusionTableRow[]{}; if (data != null){ retArray = data.toArray(new ItsaseusFusionTableRow[data.size()]); return retArray; } else{ return null; } } /** * Gets the JSON data from NOAA * @return The JSON object containing data from NOAA buoy */ @GET @Path("/get/noaa_fusion_table") @Produces(MediaType.APPLICATION_JSON) public BuoyRSSData [] getNoaaDataEntity() { ArrayList&lt;BuoyRSSData&gt; data = getDataFromNoaaTable(); BuoyRSSData [] retArray = new BuoyRSSData[]{}; if (data != null){ retArray = data.toArray(new BuoyRSSData[data.size()]); return retArray; } else{ return null; } } } </code></pre> <p>As you can see, nothing really complex here. It looks to me something more related with how to pack the JAR file so Jersey knows where to look...I tried what was suggested here: <a href="https://groups.google.com/d/msg/neo4j/0dNqGXvEbNg/xaNlRiU1cHMJ" rel="nofollow">https://groups.google.com/d/msg/neo4j/0dNqGXvEbNg/xaNlRiU1cHMJ</a> But it does not seem to work...</p> <p><strong>UPDATE:</strong> I managed to fix this by creating a hand made ANT file with the typical tasks: clean, build, jar, etc... I cannot really say what specific point of my ANT is fixing this issue...but it does. You can downloaded it <a href="https://dl.dropboxusercontent.com/u/16504598/build.xml" rel="nofollow">here</a> and reuse it if you happen to have the same problem, provided you change it accordingly to suit your project.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload