Java 瓦丁+;Spring Boot生产模式生成,出现运行时错误:无法确定';npm';工具

Java 瓦丁+;Spring Boot生产模式生成,出现运行时错误:无法确定';npm';工具,java,maven,spring-boot,docker,vaadin-flow,Java,Maven,Spring Boot,Docker,Vaadin Flow,解决方案更新 此错误似乎是问题的原因: 在推出修复程序时,标记的答案可以用作解决方法 背景 我正在为我的应用程序创建一个基于Spring Boot+Vaadin的固定化流 问题 该门户在我的机器上以Vaadin的开发模式运行,并安装了npm,但我似乎无法获得创建轻量级部署jar的正确设置,该jar已经包含所有生成的前端组件 当我在Docker容器中运行服务时,我得到一个错误,即它找不到npm,但我认为生产部署不需要它 at com.vaadin.flow.server.startup.DevMo

解决方案更新 此错误似乎是问题的原因:

在推出修复程序时,标记的答案可以用作解决方法

背景

我正在为我的应用程序创建一个基于Spring Boot+Vaadin的固定化流

问题

该门户在我的机器上以Vaadin的开发模式运行,并安装了npm,但我似乎无法获得创建轻量级部署jar的正确设置,该jar已经包含所有生成的前端组件

当我在Docker容器中运行服务时,我得到一个错误,即它找不到npm,但我认为生产部署不需要它

at com.vaadin.flow.server.startup.DevModeInitializer.initDevModeHandler(DevModeInitializer.java:327)
    at com.vaadin.flow.spring.VaadinServletContextInitializer$DevModeServletContextListener.contextInitialized(VaadinServletContextInitializer.java:323)
    ... 46 common frames omitted
Caused by: com.vaadin.flow.server.ExecutionFailedException: 

Failed to determine 'npm' tool.
Please install it either:
  - by following the https://nodejs.org/en/download/ guide to install it globally
  - or by running the frontend-maven-plugin goal to install it in this project:
  $ mvn com.github.eirslett:frontend-maven-plugin:1.7.6:install-node-and-npm -DnodeVersion="v12.13.0" 
没有npm的Docker文件

FROM openjdk:11-jre-slim

ARG PROJECT
ARG SERVICE_PORT
ARG JAR_FILE

EXPOSE ${SERVICE_PORT}

RUN mkdir /${PROJECT}
WORKDIR /${PROJECT}

ADD target/${JAR_FILE} ./app.jar

CMD ["java","-jar","app.jar"]
pom.xml(更新!)

application-prod.properties

spring.profiles.active=@activatedProperties@
vaadin.compatibilityMode=false
vaadin.servlet.productionMode=true
我感谢任何指导:)


所有代码都可以在项目公共存储库的主分支上找到:

由于我最近遇到了同样的困难,我有以下解决方案。我发现拥有Java和Nodejs/NPM的最简单方法是将其安装到Java基本映像中。这将不是一个小码头工人形象<代码>mvn clean package-生产vaadin根目录。然后编辑Dockerfile以包含安装,如下所示:


然后构建并运行映像。构建时间和图像大小将大大增加。我希望看到在这一进程中提出一些建议或取得更多进展。从Vaadin8到14已经产生了许多令人头痛的问题,因为必须了解为什么非Java的东西会被破坏

我终于找到了解决问题的办法。 正确的假设是,运行生产应用程序不需要npm。 不清楚的是,虽然将以下属性添加到prod构建概要文件中会填充到构建的jar文件中,但是

本身不会触发Vaadin在生产模式下运行(至少不会与SpringBoot一起运行):

<vaadin.productionMode>true</vaadin.productionMode>
下面是完整的、更新的、正在运行的pom.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.tlvlp</groupId>
    <artifactId>iot-portal</artifactId>
    <version>0.0.2</version>
    <name>iot-portal</name>
    <description>tlvlp IoT server portal</description>

    <properties>
        <java.version>11</java.version>
        <vaadin.version>14.0.12</vaadin.version>
        <dockerfile.maven.version>1.4.13</dockerfile.maven.version>
        <flow.server.prod.version>2.0.17</flow.server.prod.version>
        <!--    DOCKER IMAGE ARGS   -->
        <docker.project.repository>tlvlp/iot-portal</docker.project.repository>
        <service.port>8600</service.port>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-bom</artifactId>
                <version>${vaadin.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

        </plugins>
    </build>

    <profiles>
        <profile>
            <id>prod</id>
            <properties>
                <spring.activatedProperties>prod</spring.activatedProperties>
                <vaadin.productionMode>true</vaadin.productionMode>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>com.vaadin</groupId>
                    <artifactId>flow-server-production-mode</artifactId>
                    <version>${flow.server.prod.version}</version>
                </dependency>
            </dependencies>

            <build>
                <plugins>
                    <plugin>
                        <groupId>com.vaadin</groupId>
                        <artifactId>flow-maven-plugin</artifactId>
                        <version>${flow.server.prod.version}</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>prepare-frontend</goal>
                                    <goal>build-frontend</goal>

                                </goals>
                                <phase>compile</phase>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>com.spotify</groupId>
                        <artifactId>dockerfile-maven-plugin</artifactId>
                        <version>${dockerfile.maven.version}</version>
                        <executions>
                            <execution>
                                <id>prod</id>
                                <goals>
                                    <goal>build</goal>
                                    <goal>push</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <repository>${docker.project.repository}</repository>
                            <tag>${project.version}</tag>
                            <tag>latest</tag>
                            <buildArgs>
                                <PROJECT>${project.groupId}.${project.artifactId}</PROJECT>
                                <SERVICE_PORT>${service.port}</SERVICE_PORT>
                                <JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
                            </buildArgs>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>dev</id>
            <properties>
                <spring.activatedProperties>dev</spring.activatedProperties>
                <vaadin.productionMode>false</vaadin.productionMode>
            </properties>
        </profile>
    </profiles>

</project>

4.0.0
org.springframework.boot
spring启动程序父级
2.2.1.发布
com.tlvlp
物联网门户
0.0.2
物联网门户
tlvlp物联网服务器门户
11
14.0.12
1.4.13
2.0.17
tlvlp/物联网门户
8600
org.springframework.boot
弹簧启动安全
org.springframework.boot
SpringBootStarterWeb
com.vaadin
瓦丁弹簧靴起动器
org.springframework.boot
弹簧起动试验
测试
org.junit.vintage
朱尼特老式发动机
org.springframework.security
弹簧安全性试验
测试
com.vaadin
瓦丁波姆
${vaadin.version}
聚甲醛
进口
org.springframework.boot
springbootmaven插件
戳
戳
真的
真的
com.vaadin
流服务器生产模式
${flow.server.prod.version}
com.vaadin
FlowMaven插件
${flow.server.prod.version}
准备前端
构建前端
编译
com.spotify
dockerfile maven插件
${dockerfile.maven.version}
戳
建造
推
${docker.project.repository}
${project.version}
最新的
${project.groupId}.${project.artifactId}
${service.port}
${project.build.finalName}.jar
发展
发展
假的

您是否在生产模式下运行?您可以在默认情况下启用prod,如下所示:@anasmi谢谢,我正在使用prod配置文件运行maven构建,自上次更新以来,我已设法使spring引导在运行时使用prod配置文件,但Vaadin似乎仍在尝试使用dev配置文件并查找npm。我已经更新了上面的pom.xml,并添加了属性文件的相关部分。我在pom.xml中没有看到jar,oy应该在开头出现。@TatuLund它包含在spring boot starter父项目中,在我的p中被引用为父项目
spring.profiles.active=@spring.activatedProperties@
vaadin.productionMode=@vaadin.productionMode@
vaadin.compatibilityMode=false
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.tlvlp</groupId>
    <artifactId>iot-portal</artifactId>
    <version>0.0.2</version>
    <name>iot-portal</name>
    <description>tlvlp IoT server portal</description>

    <properties>
        <java.version>11</java.version>
        <vaadin.version>14.0.12</vaadin.version>
        <dockerfile.maven.version>1.4.13</dockerfile.maven.version>
        <flow.server.prod.version>2.0.17</flow.server.prod.version>
        <!--    DOCKER IMAGE ARGS   -->
        <docker.project.repository>tlvlp/iot-portal</docker.project.repository>
        <service.port>8600</service.port>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-bom</artifactId>
                <version>${vaadin.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

        </plugins>
    </build>

    <profiles>
        <profile>
            <id>prod</id>
            <properties>
                <spring.activatedProperties>prod</spring.activatedProperties>
                <vaadin.productionMode>true</vaadin.productionMode>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>com.vaadin</groupId>
                    <artifactId>flow-server-production-mode</artifactId>
                    <version>${flow.server.prod.version}</version>
                </dependency>
            </dependencies>

            <build>
                <plugins>
                    <plugin>
                        <groupId>com.vaadin</groupId>
                        <artifactId>flow-maven-plugin</artifactId>
                        <version>${flow.server.prod.version}</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>prepare-frontend</goal>
                                    <goal>build-frontend</goal>

                                </goals>
                                <phase>compile</phase>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>com.spotify</groupId>
                        <artifactId>dockerfile-maven-plugin</artifactId>
                        <version>${dockerfile.maven.version}</version>
                        <executions>
                            <execution>
                                <id>prod</id>
                                <goals>
                                    <goal>build</goal>
                                    <goal>push</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <repository>${docker.project.repository}</repository>
                            <tag>${project.version}</tag>
                            <tag>latest</tag>
                            <buildArgs>
                                <PROJECT>${project.groupId}.${project.artifactId}</PROJECT>
                                <SERVICE_PORT>${service.port}</SERVICE_PORT>
                                <JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
                            </buildArgs>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>dev</id>
            <properties>
                <spring.activatedProperties>dev</spring.activatedProperties>
                <vaadin.productionMode>false</vaadin.productionMode>
            </properties>
        </profile>
    </profiles>

</project>