Search code examples
angularmavenwarglassfish-4rest

Packaging an Angular project as a webapp with Maven


Here's a bit of a strange question : I have an Angular project that talks to a Restful Java application. I was looking for help to package it as a Maven webapp project which can then generate/build a WAR file. Is that something that can me done easily in Maven? So far I created a bare bones app using the 'maven-archetype-webapp' archtype but not entirely sure if the Angular will play nice. The goal was to take the Angular UI and deploy it on some legacy servers (like GlassFish, IBM Websphere AS 9.0 etc.) so that it works like a regular client application. Any help is greatly appreciated.


Solution

  • I've done something similar with a Vue and Dropwizard based project, set up like so:

    • front end project included in the maven structure under a client directory/module
    • client pom uses the maven exec plugin to run a frontend build (npm in my case, but grunt/gulp/yarn/whatever would work too) during the compile phase of the build
    • client pom uses the maven resources plugin to copy-resources from the frontend build output directory (dist) to a target output subdirectory (${project.build.outputDirectory}/assets) during the prepare-package phase of the build
    • client pom uses the maven jar plugin to jar the output directory during the package phase of the build
    • dropwizard module depends on the client jar, and uses AssetsBundle to serve the frontend app at /assets

    The details may differ slightly based on the best way to serve assets under Glassfish/Websphere/etc and the angular build process, but the above approach should be adaptable to those details.