如何告诉码头将部分 jar 文件提取到其上下文临时位置

How to tell jetty to extract part of the jar files into its context temp location

我已将 Jetty 嵌入到我的 Java 应用程序中,并且我创建了一个可执行 jar file.When 我从 cmd 执行 jar 文件 started.I 在 Jetty 服务器启动程序中定义如下 class.

protected void configureWebApp() throws IOException {
        File webAppDir=new File(getClass().getProtectionDomain().getCodeSource().getLocation());

      WebAppContext context = new WebAppContext(webAppDir.getPath(), "/");
        resetTempDirectory(context, currentDir);
        context.setInitParameter("development", "false");
        server.setHandler(context);
        }

protected void resetTempDirectory(WebAppContext context, File currentDir) throws IOException {
        File workDir;
        if (workPath != null) {
            workDir = new File(workPath);
        } else {
            workDir = new File(currentDir, "work");
        }
        FileUtils.deleteDirectory(workDir);
        context.setTempDirectory(workDir);
    }

当 运行 从 cmd webAppDir 设置路径指向我的应用程序时 jar.so jetty 会将所有 jar 内容提取到它的临时文件中 directory.It 似乎我在浪费资源并且减慢我的应用程序启动速度。

在我的 jar 中有一个 webApp 文件夹,其中包含与网络相关的 stuff.My 问题,

  1. 我如何指示码头只告诉提取 webApp folder 到 临时目录?
  2. 我可以关闭码头提取到临时目录并写我的 我自己的方法来提取我需要的文件夹并将该文件夹指向 jetty temp directory.I 我不确定这是否是个好主意。

我是 Jetty 的新手,请告诉我如何操作。

.

所以你不想让 Servlet 规范临时目录做它的事情,但仍然使用 Servlet 规范?

prior answer on how the temp directory works

选项 #1

这是嵌入式码头,跳过 WebAppContext(及其 Servlet 规范强制行为)并通过处理程序配置所有内容(如 ServletContextHandler)。

您将失去一些 "discover" 组件的能力,并且没有字节码扫描,但您将拥有最终的控制权,启动将以亚秒级的时间进行衡量。

选项 #2

如果这只是一个启动问题,请忽略临时目录问题,运行 在部署之前 quickstart 生成 servlet 清单,并使用(预构建的)快速入门启动 WebAppContext元数据。