2

I have spent a few days on this and I still did not find an answer (i did find questions asking for this)

I am coding with java, using a grizzly server (2.3 version) and I've managed to work with many kind of resources (restful classes, java servlets etc).

    URI uri = new URI("http://localhost....");
    ResourceConfig rc = new ResourceConfig();
    rc.registerClasses(aResource.class);
    GrizzlyHttpServerFactory.createHttpServer(uri, rc);

My goal though, is to load a whole war file and not individual classes but i have not find a way to do it.


So the question is 'how can i deploy and run a war file inside a grizzly server?'

Mario
  • 767
  • 1
  • 14
  • 42

2 Answers2

1

According to the Grizzly Javadoc you do it like this:

Synchronous Web Server servicing a Servlet

    GrizzlyWebServer ws = new GrizzlyWebServer("/var/www");
    try {
        ServletAdapter sa = new ServletAdapter();
        sa.setRootFolder("/Path/To/Exploded/War/File");
        sa.setServlet(new MyServlet());
        ws.addGrizzlyAdapter(sa);
        ws.start();
    } catch (IOException ex) {
        // Something when wrong.
    } 

However, as you can see, you first have to "explode" the WAR file; i.e. unpack it into the file system.


You seem to be using the Jersey ResourceConfig class. To make your approach work, I think you would need to do the following:

  1. Unpack the WAR file.
  2. Create a URLClassloader instance that loads from "/WEB-INF/classes" the JARs etc in "/WEB-INF/lib".
  3. Register it by calling ResourceConfig.setClassLoader

For the record, classloading from a packed WAR file is more effort, and apparently gives poor performance. (If you want to see how to do it, Tomcat has this functionality ... disabled by default.)

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • Unfortunately this is applicable to an older grizzly version (1.9) and i am using a newer one. But this is on me, since i did not specify what version i use (2.3). I have edited the question. By any chance, do you know how to do this using 2x versions? – Mario Jun 08 '15 at 12:31
  • Sorry. Don't know. It looks like they decided that running classic servlets on Grizzly was not a feature they wanted to support. (Grizzly has its own set of APIs that are intended to be used instead of the servlet APIs ...) You say that it is a "big drawback", but the same logic would say that it is a big drawback that you can't make an espresso with a teapot, – Stephen C Jun 08 '15 at 23:05
  • I think that the "espresso-teapot" is not the best comparison since i am expecting from oranges to produce orange juice, not lemon juice. Grizzly is a good empendedd Java server container that cannot handle the standard file for java Web Applications (WAR), which is kind of weird. Anyway, the outcome in this case was that i was forced to replace Grizzly with Jetty for this specific reason. – Mario Jul 02 '15 at 10:10
0

It's not possible to deploy WAR files to Grizzly 2.x at this point in time.

rlubke
  • 965
  • 5
  • 14
  • I think that this is a big drawback for grizzly.. Can you recommend any other libraries that are capable to load a war file? – Mario Jun 08 '15 at 18:03
  • Outside of a full container and Grizzly 1.9, no. – rlubke Jun 08 '15 at 22:31
  • By 'other libraries', I mean something like Jetty, which - i think - can support this kind of functionality. Thanks for your help, although it is not what 've i hoped, it is the accepted answer for this question :) – Mario Jun 09 '15 at 07:43