在Heroku上部署Vaadin 14应用程序时出现问题

时间:2019-10-25 08:41:52

标签: maven heroku deployment vaadin

在Heroku上部署Vaadin 14应用程序(春季启动)时遇到问题。这是Heroku日志:

2019-10-23T19:34:19.005415+00:00 app[web.1]: 2019-10-23 19:34:19.004 ERROR 4 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]
     : Exception sending context initialized event to listener instance of class [com.vaadin.flow.spring.VaadinServletContextInitialize
r$DevModeServletContextListener]
2019-10-23T19:34:19.005427+00:00 app[web.1]:
2019-10-23T19:34:19.005432+00:00 app[web.1]: java.lang.IllegalStateException: Running project in development mode with no access to fol
der '/tmp/build_1eb1799fb4903b1c64716231dcb4a093'.
2019-10-23T19:34:19.005435+00:00 app[web.1]: Build project in production mode instead, see https://vaadin.com/docs/v14/flow/production/
tutorial-production-mode-basic.html
2019-10-23T19:34:19.005436+00:00 app[web.1]: at com.vaadin.flow.server.DeploymentConfigurationFactory.verifyFolderExists(DeploymentConf
igurationFactory.java:283) ~[flow-server-2.0.14.jar!/:2.0.14]
2019-10-23T19:34:19.005438+00:00 app[web.1]: at com.vaadin.flow.server.DeploymentConfigurationFactory.readBuildInfo(DeploymentConfigura
tionFactory.java:222) ~[flow-server-2.0.14.jar!/:2.0.14]
2019-10-23T19:34:19.005439+00:00 app[web.1]: at com.vaadin.flow.server.DeploymentConfigurationFactory.createInitParameters(DeploymentCo
nfigurationFactory.java:166) ~[flow-server-2.0.14.jar!/:2.0.14]
2019-10-23T19:34:19.005441+00:00 app[web.1]: at com.vaadin.flow.server.DeploymentConfigurationFactory.createPropertyDeploymentConfigura
tion(DeploymentConfigurationFactory.java:126) ~[flow-server-2.0.14.jar!/:2.0.14]
2019-10-23T19:34:19.005445+00:00 app[web.1]: at com.vaadin.flow.spring.VaadinServletContextInitializer$SpringStubServletConfig.createDe
ploymentConfiguration(VaadinServletContextInitializer.java:747) ~[vaadin-spring-12.0.6.jar!/:na]
2019-10-23T19:34:19.005447+00:00 app[web.1]: at com.vaadin.flow.spring.VaadinServletContextInitializer$DevModeServletContextListener.co
ntextInitialized(VaadinServletContextInitializer.java:289) ~[vaadin-spring-12.0.6.jar!/:na]
2019-10-23T19:34:19.005449+00:00 app[web.1]: at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4680) [tomc
at-embed-core-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.00545+00:00 app[web.1]: at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5143) [tomca
t-embed-core-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.005451+00:00 app[web.1]: at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core
-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.005452+00:00 app[web.1]: at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384) [tomcat
-embed-core-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.005454+00:00 app[web.1]: at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374) [tomcat
-embed-core-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.005456+00:00 app[web.1]: at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_222-heroku]
2019-10-23T19:34:19.005457+00:00 app[web.1]: at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java
:75) [tomcat-embed-core-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.005458+00:00 app[web.1]: at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) [
na:1.8.0_222-heroku]
2019-10-23T19:34:19.00546+00:00 app[web.1]: at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909) [tomcat-emb
ed-core-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.005461+00:00 app[web.1]: at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:841) [tomcat-embe
d-core-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.005462+00:00 app[web.1]: at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core
-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.005464+00:00 app[web.1]: at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384) [tomcat
-embed-core-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.005465+00:00 app[web.1]: at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374) [tomcat
-embed-core-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.005466+00:00 app[web.1]: at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_222-heroku]
2019-10-23T19:34:19.005467+00:00 app[web.1]: at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java
:75) [tomcat-embed-core-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.005469+00:00 app[web.1]: at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) [
na:1.8.0_222-heroku]
2019-10-23T19:34:19.00547+00:00 app[web.1]: at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909) [tomcat-emb
ed-core-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.005472+00:00 app[web.1]: at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262) [tomcat-
embed-core-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.005473+00:00 app[web.1]: at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core
-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.005474+00:00 app[web.1]: at org.apache.catalina.core.StandardService.startInternal(StandardService.java:421) [tomca
t-embed-core-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.005475+00:00 app[web.1]: at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core
-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.005485+00:00 app[web.1]: at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:932) [tomcat-
embed-core-9.0.22.jar!/:9.0.22]
2019-10-23T19:34:19.005487+00:00 app[web.1]: at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core
-9.0.22.jar!/:9.0.22]

由于记录问题,问题在于生产模式。但是我已经将Heroku SPRING_PROFILES_ACTIVE环境变量设置为生产环境。

heroku config:set SPRING_PROFILES_ACTIVE=production

这是pom.xml(构建和配置文件部分):

<build>
    <defaultGoal>spring-boot:run</defaultGoal>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <!-- Clean build and startup time for Vaadin apps sometimes may exceed
                 the default Spring Boot's 30sec timeout.  -->
            <configuration>
                <wait>500</wait>
                <maxAttempts>240</maxAttempts>
            </configuration>
        </plugin>

        <!--
            Take care of synchronizing java dependencies and imports in
            package.json and main.js files.
            It also creates webpack.config.js if not exists yet.
        -->
        <plugin>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-maven-plugin</artifactId>
            <version>${vaadin.version}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>prepare-frontend</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>com.github.eirslett</groupId>
            <artifactId>frontend-maven-plugin</artifactId>
            <!-- Use the latest released version:
            https://repo1.maven.org/maven2/com/github/eirslett/frontend-maven-plugin/ -->
            <version>1.8.0</version>

            <executions>
                <execution>
                    <!-- optional: you don't really need execution ids, but it looks nice in your build log. -->
                    <id>install node and npm</id>
                    <goals>
                        <goal>install-node-and-npm</goal>
                    </goals>
                    <!-- optional: default phase is "generate-resources" -->
                    <phase>generate-resources</phase>
                </execution>
            </executions>
            <configuration>
                <nodeVersion>v10.16.2</nodeVersion>

                <!-- optional: with node version greater than 4.0.0 will use npm provided by node distribution -->
                <!--                    <npmVersion>2.15.9</npmVersion>-->

                <!-- optional: where to download node and npm from. Defaults to https://nodejs.org/dist/ -->
                <!--                    <downloadRoot>http://myproxy.example.org/nodejs/</downloadRoot>-->
            </configuration>
        </plugin>
    </plugins>
</build>

<profiles>
    <profile>
        <id>production</id>
        <properties>
            <vaadin.productionMode>true</vaadin.productionMode>
        </properties>
        <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>prepare-frontend</goal>
                                <goal>build-frontend</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

我在做什么错?在Heroku上部署Vaadin 13应用程序时,我没有任何问题。

已解决的编辑问题 通过运行命令解决的问题

mvn clean package -Pproduction heroku:deploy

1 个答案:

答案 0 :(得分:0)

通过执行以下步骤解决了该问题:

在pom.xml文件的构建标记中添加frontend-maven-plugin

<plugins>
    <plugin>
        <groupId>com.github.eirslett</groupId>
        <artifactId>frontend-maven-plugin</artifactId>
          <!-- Use the latest released version:

          https://repo1.maven.org/maven2/com/github/eirslett/frontend-maven-plugin/ -->
        <version>LATEST_VERSION</version>
        ...
    </plugin>
…

通过添加执行目标和节点版本来配置此插件

<executions>
   <execution>
       <id>install node and npm</id>
       <goals>
           <goal>install-node-and-npm</goal>
       </goals>
       <phase>generate-resources</phase>
   </execution>
</executions>
<configuration>
     <nodeVersion>v10.16.2</nodeVersion>
</configuration>

在vaadin-maven-plugin的生产配置文件中,添加执行目标prepare-frontend

<profiles>
   <profile>
       <id>production</id>
       <properties>
           <vaadin.productionMode>true</vaadin.productionMode>
       </properties>
       <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>prepare-frontend</goal>
                               <goal>build-frontend</goal>
                           </goals>
                       </execution>
                   </executions>
               </plugin>
…

最后,使用以下配置添加heroku-maven-plugin

<plugin>
   <groupId>com.heroku.sdk</groupId>
   <artifactId>heroku-maven-plugin</artifactId>
   <version>2.0.13</version>
   <configuration>
       <appName>vaadin-heroku-app</appName>
       <processTypes>
        <web>java $JAVA_OPTS -jar target/<project_name>.jar --server.port=$PORT</web>
       </processTypes>
   </configuration>
</plugin>

Heroku-maven-plugin可将预先打包的独立Web应用程序直接部署到Heroku。

标记appName是Heroku应用程序的名称,仅当您的应用程序不受Git版本控制时才是必需的。

标记processTypes告诉Heroku启动Web进程并运行.jar文件。

要将生产模式下的Vaadin应用程序部署到Heroku,请从项目目录输入以下命令

mvn clean package -Pproduction heroku:deploy

更多详细信息在这里:[https://ramonak.io/how-to-deploy-vaadin-14-app-to-heroku/][1]