exec-maven-pluginによって、 AngularJS 2 + Spring Bootアプリケーションで npm プロセスが機能するようにしました。私は bower と grunt を使用しませんが、上記の Pear の antrun の例を見て、exec-maven-plugin でも動作させることができると思います。
以下は、exec-maven-plugin の pom.xml の例です。私のアプリには package.json があり、すべての AngularJS .ts ファイルは src/main/resources の下にあるため、パスから npm を実行します。依存関係のためにnpm installを実行し、.ts から .js への変換のためにnpm run tscを実行します
pom.xml
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>exec-npm-install</id>
<phase>generate-sources</phase>
<configuration>
<workingDirectory>${project.basedir}/src/main/resources</workingDirectory>
<executable>npm</executable>
<arguments>
<argument>install</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
<execution>
<id>exec-npm-run-tsc</id>
<phase>generate-sources</phase>
<configuration>
<workingDirectory>${project.basedir}/src/main/resources</workingDirectory>
<executable>npm</executable>
<arguments>
<argument>run</argument>
<argument>tsc</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
これに関する小さなハックの 1 つは、Windows または Mac の Eclipse で Maven ビルドを実行することです。Linuxを使用したEclipseでは完全に問題なく、Windowsコマンドウィンドウでも問題ありません。Windows で eclipse でビルドを実行すると、npmを認識できず、ファイルが見つからないというエラーが表示されます。奇妙なことに、npmは Windows コマンド ウィンドウで正常に動作しています。ハックを解決して、システムパスの下にnpm.batファイルを作成します。私の場合、nodejs と npm は C:\Program File\nodejs の下にインストールされています。このバッチファイルを入れた後。すべて正常に動作します。
npm.bat
@echo off
set arg1=%1
set arg2=%2
C:\Progra~1\nodejs\npm.cmd %arg1% %arg2%
Mac の場合、Eclipse でも同じ問題が発生しました。nodejs と npm は /usr/local/bin の下にインストールされています。この問題を解決するために、シンボリック リンク /usr/local/bin/node と /usr/local/bin/npm を /user/bin の下に作成します。ただし、/usr/bin はセキュリティ ポリシーで保護されているため、リカバリ ディスクから起動した後にこれを行いました。