简体   繁体   中英

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. you can ignore the WEB-INF/lib folder since angular don't need any java library.

You can try using grunt for angular-grunt-build. Please refer 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. Build plugins will be executed during the build and they should be configured in the element from the 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. If not the maven build will fail because it will not find the environment need to run a build of angular app.

After that we modify the maven-war-plugin. The directory that we specify below will be location angular app in war generated by maven build.

            <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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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