如何将vue dist文件夹部署到GlassFish 5?

时间:2019-12-18 14:40:06

标签: java vue.js java-ee glassfish jakarta-ee

我正在尝试寻找一种在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问题。

我的休息/后端项目是用Maven构建的,是一场战争。

1 个答案:

答案 0 :(得分:1)

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

我对在Payara上运行的React + Jakarta EE应用程序(与Glassfish相似)进行了以下设置(您可能需要将其调整为文件夹结构):

<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上找到。

相关问题