exec-maven-plugin with npm install
Instead of using exec-maven-plugin
, I suggest you to take a look at the frontend-maven-plugin
to build your Node sources using npm install
.
Using that plugin, you don't need to have npm
or node
installed on your machine : the plugin manages all by itself, so you should not encounter issues like command not found
. Configuration like the following should work :
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.6</version>
<configuration>
<workingDirectory>src/main/angular5/tourism</workingDirectory>
<!-- where to install npm -->
<installDirectory>${project.build.directory}/install</installDirectory>
</configuration>
<executions>
<execution>
<id>install-node-and-npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>v${node.version}</nodeVersion>
<npmVersion>${npm.version}</npmVersion>
</configuration>
</execution>
<execution>
<id>npm-install</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
</executions>
</plugin>
Related videos on Youtube
flamant
Updated on June 04, 2022Comments
-
flamant almost 2 years
I try to use exec-maven-plugin in my project.
Here is the code
<plugin> <artifactId>exec-maven-plugin</artifactId> <groupId>org.codehaus.mojo</groupId> <version>1.6.0</version> <executions> <execution> <id>npm install</id> <goals> <goal>exec</goal> </goals> <phase>generate-resources</phase> <configuration> <executable>${node.directory}/${npm.executable}</executable> <arguments> <argument>install</argument> </arguments> <workingDirectory>src/main/angular2/tourism</workingDirectory> <target> <echo message="Npm install" /> </target> </configuration> </execution> </executions> </plugin>
Here is my directory structure
And the mentioned error is
/Users/admin/Application-Marwen/workspace/Tourism/Tourism-Web/node/npm: line 34: node: command not found
Could you please help me
I use know frontend-maven-plugin
Here is the code
<plugin> <groupId>com.github.eirslett</groupId> <artifactId>frontend-maven-plugin</artifactId> <version>1.6</version> <configuration> <workingDirectory>src/main/angular5/tourism</workingDirectory> <!-- where to install npm --> <installDirectory>src/main/angular5/tourisml</installDirectory> </configuration> <executions> <execution> <id>install node and npm</id> <goals> <goal>install-node-and-npm</goal> </goals> <phase>generate-resources</phase> <configuration> <nodeVersion>v8.11.3</nodeVersion> <npmVersion>6.3.0</npmVersion> </configuration> </execution> <execution> <id>npm install</id> <goals> <goal>npm</goal> </goals> <!-- Optional configuration which provides for running any npm command --> <configuration> <arguments>install</arguments> <workingDirectory>src/main/angular5/tourism</workingDirectory> </configuration> </execution> <execution> <id>prod</id> <goals> <goal>npm</goal> </goals> <configuration> <arguments>run-script build</arguments> <workingDirectory>src/main/angular5/tourism</workingDirectory> </configuration> <phase>generate-resources</phase> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <configuration> <finalName>${project.artifactId}-${project.version}.zip</finalName> <appendAssemblyId>false</appendAssemblyId> </configuration> <executions> <execution> <id>cfg-main-resources</id> <goals> <goal>single</goal> </goals> <phase>package</phase> <configuration> <descriptors> <descriptor>${basedir}/src/main/angular5/tourism/assembly.xml</descriptor> </descriptors> </configuration> </execution> </executions> </plugin>
And the assembly.xml file
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd"> <id>distribution</id> <formats> <format>zip</format> </formats> <includeBaseDirectory>false</includeBaseDirectory> <fileSets> <fileSet> <outputDirectory>statics</outputDirectory> <directory>dist</directory> <includes> <include>**/*</include> </includes> </fileSet> </fileSets>
The objective is to prepare a zip file containing the compiled code to deploy it on server
Here is the obtained directory structure
1) I don't understand why the dist folder does not contain the compiled code (I wonder furthermore what it must contain exactly) 2) node and npm are installed in the directory tourisml/node, why 3) there is an error stating that
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.4:single (cfg-main-resources) on project tourism-web: Failed to create assembly: Error creating assembly archive distribution: You must set at least one file. -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.4:single (cfg-main-resources) on project tourism-web: Failed to create assembly: Error creating assembly archive distribution: You must set at least one file.
Normally I should obtaine one zip file (${project.artifactId}-${project.version}.zip) and I suppose it failed because there is no files in. Is that correct ?
-
flamant over 5 yearsHello norbjd, I added some more information in the first post
-
-
flamant over 5 yearsHello, I tried to use frontend-maven-plugin, but I have the same issue(I obtained the same directory structure): [ERROR] Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.6:npm (npm install) on project tourism-web: Failed to run task: 'npm install' failed. java.io.IOException: Cannot run program "/Users/admin/Application-Marwen/workspace/Tourism/Tourism-Web/src/main/angular5/tourism/node/node" (in directory "/Users/admin/Application-Marwen/workspace/Tourism/Tourism-Web/src/main/angular5/tourism"): error=2, No such file or directory -> [Help 1]
-
norbjd over 5 years@flamant Just updated the answer with an example of configuration
-
Robin over 5 yearsWhat if you are working behind your companies proxy then frontend-maven-plugin wont be ideal as it will give proxy errors
-
Milad Naseri over 3 yearsI suggest that you accept the answer above so that (1) other people are not confused when looking up the content and (2) the person who shared their knowledge here feels appreciated.