Приложение Vaadin 14 не загружает файлы cache.js, вызывая пустую страницу - PullRequest
0 голосов
/ 11 октября 2019

Когда я пытаюсь загрузить свое приложение в Vaadin 14, я вижу такой пустой экран ...

enter image description here

Похоже, что контейнер сервлетана самом деле работает, но не может разместить некоторые статические ресурсы ...

Когда я смотрю на вкладку сети в Инспекторе Chrome, я вижу, что не может найти несколько файлов, таких как

http://localhost:8080/VAADIN/static/client/client-122CE29AC0B9685B4DC485343E774096.cache.js

enter image description here

Я не уверен, почему это так. Любые идеи?

ОБНОВЛЕНИЕ:

Похоже, я должен вручную убедиться, что все мои файлы .jar добавлены в качестве ресурсов в молнии, чтобы статический контент можно было обслуживать. Я попытался сделать это так, и он отлично работает на моем ноутбуке, но не на сервере ...

public class App {


public static void main(String[] args) throws Exception {
    final var server = new Server(8080);

    // Specifies the order in which the configurations are scanned.
    Configuration.ClassList classlist = Configuration.ClassList.setServerDefault(server);
    classlist.addAfter("org.eclipse.jetty.webapp.FragmentConfiguration", "org.eclipse.jetty.plus.webapp.EnvConfiguration", "org.eclipse.jetty.plus.webapp.PlusConfiguration");
    classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.annotations.AnnotationConfiguration");

    // Creation of a temporal directory.
    File tempDir = new File(System.getProperty("java.io.tmpdir"), "JettyTest");
    if (tempDir.exists()) {
        if (!tempDir.isDirectory()) {
            throw new RuntimeException("Not a directory: " + tempDir);
        }
    } else if (!tempDir.mkdirs()) {
        throw new RuntimeException("Could not make: " + tempDir);
    }

    WebAppContext context = new WebAppContext();
    context.setInitParameter("productionMode", "false");
    // Context path of the application.
    context.setContextPath("");
    // Exploded war or not.
    context.setExtractWAR(false);
    context.setTempDirectory(tempDir);

    // It pulls the respective config from the VaadinServlet.
    context.addServlet(GuiceVaadinServlet.class, "/*").setInitOrder(1);

    context.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*");

    context.setParentLoaderPriority(true);
    server.setHandler(context);

    // This add jars to the jetty classpath in a certain syntax and the pattern makes sure to load all of them.
    final var classpathEntries = ClassPathHelper.getAllClassPathEntries();
    final var ideMode = classpathEntries.size() > 1;
    final var resourceList = new ArrayList<Resource>();
    final var jarFiles = new ArrayList<File>();

    if (ideMode) {
        System.out.println("Starting in IDE Mode");
        for (String entry : ClassPathHelper.getAllClassPathEntries()) {
            if (entry.endsWith(".jar")) {
                final var file = new File(entry);
                jarFiles.add(file);
            }
        }
    } else {
        final var baseInstallDir = System.getProperty("user.dir");
        System.out.println("Starting in Server WebJar Mode");
        final var libsDirectory = new File(baseInstallDir, "lib");
        System.out.println("Scanning for jars in " + libsDirectory.getPath());
        for (File file : Objects.requireNonNull(libsDirectory.listFiles())) {
            if (file.getPath().endsWith(".jar")) {
                jarFiles.add(file);
            }
        }
        final var sferionJar = new File(baseInstallDir, "sferion.jar");
        jarFiles.add(sferionJar);
        System.out.println("Found " + jarFiles.size() + " jar files");
    }

    for (File jarFile : jarFiles) {
        resourceList.add(Resource.newResource("jar:" + jarFile.toURI().toURL() + "!/"));
    }

    if (ideMode) {
        // It adds the web application resources. Styles, client-side components, ...
        //TODO: make this property dynamic somehow?
        resourceList.add(Resource.newResource("/usr/local/code/sferion/planglobal/src/main/webapp"));
    }

    // The base resource is where jetty serves its static content from.
    context.setBaseResource(new ResourceCollection(resourceList.toArray(new Resource[0])));

    server.start();
    server.join();
}

}

...