简体   繁体   English

如何将 Angular 8 项目构建为 .war 文件

[英]How to build angular 8 project as .war file

我想知道如何将 angular 应用程序构建为 .war 文件,以便我可以使用 maven 部署到 WAS 服务器

A war file structure will be as below战争文件结构如下

Root/ - Web resources.
    WEB-INF/ - directory for application support
       lib/ - supporting jar files
       web.xml - configuration file for the application

Place your html, js and css files in the root of the war file which will be served as web resources.将您的 html、js 和 css 文件放在将作为 Web 资源提供的 war 文件的根目录中。 you can ignore the WEB-INF/lib folder since angular don't need any java library.您可以忽略 WEB-INF/lib 文件夹,因为 angular 不需要任何 java 库。

You can try using grunt for angular-grunt-build.您可以尝试使用 grunt 进行 angular-grunt-build。 Please refer https://www.npmjs.com/package/angular-grunt-build请参考https://www.npmjs.com/package/angular-grunt-build

You can do this with maven by creating a build plugin for executing the build of angular application.您可以使用 maven 创建一个构建插件来执行 angular 应用程序的构建。 Build plugins will be executed during the build and they should be configured in the element from the POM.构建插件将在构建期间执行,它们应该在 POM 的元素中进行配置。


    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>npm install</id>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <phase>install</phase>
                        <configuration>
                            <executable>npm</executable>
                            <arguments>
                                <argument>install</argument>
                            </arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>npm build</id>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <phase>install</phase>
                        <configuration>
                            <executable>npm</executable>
                            <arguments>
                                <argument>run</argument>
                                <argument>build</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

It is important for you to have already installed the node js, npm before.重要的是你之前已经安装了 node js,npm。 If not the maven build will fail because it will not find the environment need to run a build of angular app.如果不是,maven 构建将失败,因为它找不到运行 angular 应用程序构建的环境。

After that we modify the maven-war-plugin.之后我们修改maven-war-plugin。 The directory that we specify below will be location angular app in war generated by maven build.我们在下面指定的目录将是 maven build 生成的 war 中的 location angular app。

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <webResources>

                        <resource>
                            <targetPath>resources</targetPath>
                            <filtering>false</filtering>
                            <!-- this is relative to the pom.xml directory -->
                            <directory>../path when you want to put angular app /dist/</directory>
                            <includes>
                                <include>**/*.*</include>
                            </includes>
                        </resource
                    </webResources>
                </configuration>
            </plugin>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM