0

The application is packaged as executable jar, but it can't find the webapp directory that is included with the fat jar. so I must include the web app in the same directory as the fat jar.

I suspect the issue has to do with this code:

  public void init(String host, int port) throws Exception {
    logger.info("Starting Server bound to '" + host + ":" + port + "'");

    String memory = Configurations.get("refine.memory");
    if (memory != null) {
        logger.info("refine.memory size: " + memory + " JVM Max heap: " + Runtime.getRuntime().maxMemory());
    }

    int maxThreads = Configurations.getInteger("refine.queue.size", 30);
    int maxQueue = Configurations.getInteger("refine.queue.max_size", 300);
    long keepAliveTime = Configurations.getInteger("refine.queue.idle_time", 60);

    LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(maxQueue);

    threadPool = new ThreadPoolExecutor(maxThreads, maxQueue, keepAliveTime, TimeUnit.SECONDS, queue);

    this.setThreadPool(new ThreadPoolExecutorAdapter(threadPool));

    Connector connector = new SocketConnector();
    connector.setPort(port);
    connector.setHost(host);
    connector.setMaxIdleTime(Configurations.getInteger("refine.connection.max_idle_time",60000));
    connector.setStatsOn(false);
    this.addConnector(connector);

    File webapp = new File("webapp");

  final String contextPath = Configurations.get("refine.context_path","/");
  final int maxFormContentSize = Configurations.getInteger("refine.max_form_content_size", 1048576);

  logger.info("Initializing context: '" + contextPath + "' from '" + webapp.getAbsolutePath() + "'");

  WebAppContext context = new WebAppContext();

  URL webRootLocation = this.getClass().getResource("/webapp");
  if (webRootLocation == null)
  {
      throw new IllegalStateException("Unable to determine webroot URL location");
  }

  URI webRootUri = URI.create(webRootLocation.toURI().toASCIIString());

  System.err.printf("Web Root location: %s%n",webRootLocation);
  System.err.printf("Web Root URI: %s%n",webRootUri);

  context.setContextPath(webRootLocation.toString());
  context.setBaseResource(Resource.newResource(webRootLocation));
  context.setMaxFormContentSize(maxFormContentSize);
    this.setHandler(context);

    this.setHandler(context);
    this.setStopAtShutdown(true);
    this.setSendServerVersion(true);

    // Enable context autoreloading
    if (Configurations.getBoolean("refine.autoreload",false)) {
        scanForUpdates(webapp, context);
    }

    // start the server
    try {
        this.start();
    } catch (BindException e) {
        logger.error("Failed to start server - is there another copy running already on this port/address?");
        throw e;
    }

    configure(context);
}

I found what seems to be a possible solution is this SO, am I on the right path ? how would I fix this ?


Edit

I modified the code following advice given here and web searches, but now I get the following errors:

@-ThinkPad-T450s:~/projects/github/OpenRefine/fatjar$ java -jar openrefinefat.jar 
10:54:47.405 [            refine_server] Starting Server bound to '127.0.0.1:3333' (0ms)
10:54:47.416 [            refine_server] Initializing context: '/' from '/home/me/projects/github/OpenRefine/fatjar/webapp' (11ms)
Web Root location: jar:file:/home/me/projects/github/OpenRefine/fatjar/openrefinefat.jar!/webapp
Web Root URI: jar:file:/home/me/projects/github/OpenRefine/fatjar/openrefinefat.jar!/webapp
10:54:48.506 [                   refine] Starting OpenRefine trunk [TRUNK]... (1090ms)
10:54:48.537 [..enrefinefat.jar!/webapp] unavailable (31ms)
java.lang.NullPointerException
    at java.io.File.<init>(File.java:277)
    at edu.mit.simile.butterfly.Butterfly.init(Butterfly.java:191)
    at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:440)
    at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:263)
    at com.google.refine.RefineServer.configure(Refine.java:328)
    at com.google.refine.RefineServer.init(Refine.java:242)
    at com.google.refine.Refine.init(Refine.java:117)
    at com.google.refine.Refine.main(Refine.java:111)
10:54:48.543 [          org.mortbay.log] Nested in javax.servlet.ServletException: java.lang.NullPointerException: (6ms)
java.lang.NullPointerException
    at java.io.File.<init>(File.java:277)
    at edu.mit.simile.butterfly.Butterfly.init(Butterfly.java:191)
    at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:440)
    at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:263)
    at com.google.refine.RefineServer.configure(Refine.java:328)
    at com.google.refine.RefineServer.init(Refine.java:242)
    at com.google.refine.Refine.init(Refine.java:117)
    at com.google.refine.Refine.main(Refine.java:11
Created new window in existing browser session.
Community
  • 1
  • 1
InsaneBot
  • 2,422
  • 2
  • 19
  • 31

1 Answers1

0

You are missing the WebAppContext.setBaseResource(Resource) call.

This is how the WebAppContext, and the ServletContext finds its static resources, as well as any configuration resources that are specific to that context.

Joakim Erdfelt
  • 46,896
  • 7
  • 86
  • 136