【问题标题】:How to deploy vue dist folder to GlassFish 5?如何将 vue dist 文件夹部署到 GlassFish 5?
【发布时间】:2019-12-18 14:40:06
【问题描述】:

我正在想办法在 GlassFish 5 上部署我的 vue 项目。 原因是我有两个项目。在 GlassFish 上运行的基于 Java 的 REST 项目。还有一个纯 Vue 项目,之前在 node.js 上运行。

由于 2 个不同的主机,我不得不一次又一次地与 CORS 问题作斗争,我想将这两个项目合并到一台服务器上。

如果我在 Vue Docs (how to create dist folder) 中正确理解了这一点,那么首先我必须使用 serve -s dist 创建一个 dist 文件夹。

我要如何处理这个文件夹才能将它部署到我的 GlassFish 服务器上?

目标是我可以继续在我的纯 Vue 项目中开发前端,然后从中创建一个新的 dist 文件夹,然后将其移动到我需要通过 GlassFish 服务器提供的任何位置。

从那里,我调用了我的休息界面而没有遇到任何 CORS 问题。

我的 rest/backend 项目是用 Maven 构建的,是一场战争。

【问题讨论】:

    标签: java vue.js jakarta-ee glassfish


    【解决方案1】:

    您可以使用 frontend-maven-plugin 在 Maven 构建中捆绑前端构建步骤。只需使用此 Maven 插件执行构建 Vue 应用程序的命令(例如 npm run build),并配置 .war 文件以将 dist 文件夹作为 Web 资源包含。

    我为在 Payara(类似于 Glassfish)上运行的 React + Jakarta EE 应用程序做了同样的事情,设置如下(您可能需要将其调整为您的文件夹结构):

    <project>
    
      <!-- dependencies like seen above -->
    
      <build>
        <finalName>jakarta-ee-react-file-handling</finalName>
        <plugins>
          <plugin>
            <groupId>com.github.eirslett</groupId>
            <artifactId>frontend-maven-plugin</artifactId>
            <version>1.8.0</version>
            <executions>
              <execution>
                <id>install node and npm</id>
                <goals>
                  <goal>install-node-and-npm</goal>
                </goals>
                <phase>generate-resources</phase>
              </execution>
              <execution>
                <id>npm install</id>
                <goals>
                  <goal>npm</goal>
                </goals>
                <phase>generate-resources</phase>
                <configuration>
                  <arguments>install</arguments>
                </configuration>
              </execution>
              <execution>
                <id>npm test</id>
                <goals>
                  <goal>npm</goal>
                </goals>
                <phase>generate-resources</phase>
                <configuration>
                  <environmentVariables>
                    <CI>true</CI>
                  </environmentVariables>
                  <arguments>test</arguments>
                </configuration>
              </execution>
              <execution>
                <id>npm build</id>
                <goals>
                  <goal>npm</goal>
                </goals>
                <phase>generate-resources</phase>
                <configuration>
                  <environmentVariables>
                    <CI>true</CI>
                  </environmentVariables>
                  <arguments>run build</arguments>
                </configuration>
              </execution>
            </executions>
            <configuration>
              <workingDirectory>src/main/frontend</workingDirectory>
              <nodeVersion>v12.13.1</nodeVersion>
            </configuration>
          </plugin>
          <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
          </plugin>
          <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.2</version>
          </plugin>
          <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>3.2.3</version>
            <configuration>
              <webResources>
                <resource>
                  <directory>${project.basedir}/src/main/frontend/build</directory>
                </resource>
              </webResources>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </project>
    

    我还在bundling the frontend build with a Jakarta EE backend 上写了一个指南,源代码也可以在GitHub 上找到。

    【讨论】:

      猜你喜欢
      • 2021-07-12
      • 1970-01-01
      • 2019-02-13
      • 2017-11-01
      • 2022-08-04
      • 2013-09-23
      • 2015-05-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多