应用程序打包为可执行jar,但找不到fat jar附带的webapp
目录。所以我必须将web应用程序包含在与胖罐相同的目录中。
我怀疑这个问题与此代码有关:
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);
}
我发现似乎可能的解决方案是SO, 我在正确的道路上吗?我该如何解决这个问题?
我按照此处提供的建议和网络搜索修改了代码,但现在我收到以下错误:
@-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.
答案 0 :(得分:0)
您错过了WebAppContext.setBaseResource(Resource)
来电。
这是WebAppContext
和ServletContext
查找其静态资源的方式,以及特定于该上下文的任何配置资源。