在我的Kotlin码头项目中,我由maven构建。 我需要在生产模式下开始应用。 (从这里https://vaadin.com/docs/flow/production/tutorial-production-mode-basic.html) 结果是我的pom.xml
<profiles>
<profile>
<id>production-mode</id>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-server-production-mode</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-maven-plugin</artifactId>
<version>${vaadin.version}</version>
<executions>
<execution>
<goals>
<goal>copy-production-files</goal>
<goal>package-for-production</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
因此要通过Maven以生产模式启动,我使用命令:
mvn jetty:run-exploded -Pproduction-mode
,我的Web应用程序以生产模式启动。 很好。
但是我也需要创建可执行jar(或war)以从控制台启动Web应用程序。
因此,我使用了maven的插件“ maven-shade-plugin
”
因此,在我的pom.xml中添加:
plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.myproject.AppStarterKt</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
并在生产模式下创建jar:
mvn verify -Pproduction-mode
结果我得到了满足所有依赖关系的独立(可运行)jar。很好。
但是当我想像这样在生产模式下启动独立jar时:
java -Dvaadin.productionMode=true -jar myproject-1.0-SNAPSHOT.jar
但是我得到了错误:
[qtp1495242910-15] WARN org.eclipse.jetty.server.handler.ContextHandler.ROOT - unavailable
java.lang.IllegalArgumentException: Failed to find the bundle manifest file 'frontend://vaadin-flow-bundle-manifest.json' in the servlet context for 'ES6' browsers. If you are running a dev-mode servlet container in maven e.g. `jetty:run` change it to `jetty:run-exploded`. If you are not compiling frontend resources, include the 'vaadin-maven-plugin' in your build script. Otherwise, you can skip this error either by disabling production mode, or by setting the servlet parameter 'original.frontend.resources=true'.
at com.vaadin.flow.server.startup.BundleFilterFactory.readBundleManifest(BundleFilterFactory.java:89)
at com.vaadin.flow.server.startup.BundleFilterFactory.createBundleFilterForBrowser(BundleFilterFactory.java:79)
at com.vaadin.flow.server.startup.BundleFilterFactory.createFilters(BundleFilterFactory.java:70)
at com.vaadin.flow.server.VaadinService.init(VaadinService.java:275)
at com.vaadin.flow.server.VaadinServlet.createServletService(VaadinServlet.java:201)
at com.vaadin.flow.server.VaadinServlet.createServletService(VaadinServlet.java:182)
at com.vaadin.flow.server.VaadinServlet.init(VaadinServlet.java:72)
at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:672)
at org.eclipse.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:521)
at org.eclipse.jetty.servlet.ServletHolder.prepare(ServletHolder.java:805)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:537)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:146)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1588)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1345)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:480)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1557)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1247)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)
at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:61)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.eclipse.jetty.server.Server.handle(Server.java:502)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:364)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:765)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:683)
at java.lang.Thread.run(Unknown Source)
[qtp1495242910-15] WARN org.eclipse.jetty.server.HttpChannel - /booking-v2
javax.servlet.ServletException: com.vaadin.flow.server.startup.ServletDeployer@a1f5568f==com.vaadin.flow.server.VaadinServlet,jsp=null,order=-1,inst=false,async=true
at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:693)
at org.eclipse.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:521)
at org.eclipse.jetty.servlet.ServletHolder.prepare(ServletHolder.java:805)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:537)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:146)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1588)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1345)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:480)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1557)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1247)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)
at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:61)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.eclipse.jetty.server.Server.handle(Server.java:502)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:364)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:765)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:683)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: Failed to find the bundle manifest file 'frontend://vaadin-flow-bundle-manifest.json' in the servlet context for 'ES6' browsers. If you are running a dev-mode servlet container in maven e.g. `jetty:run` change it to `jetty:run-exploded`. If you are not compiling frontend resources, include the 'vaadin-maven-plugin' in your build script. Otherwise, you can skip this error either by disabling production mode, or by setting the servlet parameter 'original.frontend.resources=true'.
at com.vaadin.flow.server.startup.BundleFilterFactory.readBundleManifest(BundleFilterFactory.java:89)
at com.vaadin.flow.server.startup.BundleFilterFactory.createBundleFilterForBrowser(BundleFilterFactory.java:79)
at com.vaadin.flow.server.startup.BundleFilterFactory.createFilters(BundleFilterFactory.java:70)
at com.vaadin.flow.server.VaadinService.init(VaadinService.java:275)
at com.vaadin.flow.server.VaadinServlet.createServletService(VaadinServlet.java:201)
at com.vaadin.flow.server.VaadinServlet.createServletService(VaadinServlet.java:182)
at com.vaadin.flow.server.VaadinServlet.init(VaadinServlet.java:72)
at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:672)
答案 0 :(得分:1)
在生产构建期间,vaadin-maven-plugin
创建一个生产包,并将生成的文件放入/target/<nameAndVersion>/
中,以便在以.war
部署时,这些文件可用作静态资源。当打包为jar文件并嵌入servlet容器时,您需要配置插件以将这些文件放在其他位置。
使用哪个位置取决于嵌入式servlet容器的配置方式。一种很流行的选择是使用META-INF/resources
。要使其以这种方式工作,您可以将插件的transpileOutputDirectory
配置参数设置为${project.build.outputDirectory}/META-INF/resources
。