我尝试在我的项目中使用exec-maven-plugin。
以下是代码
<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>下面是我的目录结构

上面提到的错误是
/Users/admin/Application-Marwen/workspace/Tourism/Tourism-Web/node/npm: line 34: node: command not found你能帮帮我吗?
我使用know前端-maven-plugin
以下是代码
<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>和assembly.xml文件
<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>
目标是准备一个包含已编译代码的zip文件,以便将其部署到服务器上
下面是获得的目录结构

1)我不明白为什么dist文件夹没有包含编译后的代码(我还想知道它到底必须包含什么) 2) node和npm安装在tourisml/node目录中,为什么3)有一个错误,说明
[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.通常我应该得到一个压缩文件(${project.artifactId}-${project.version}.zip),我想它失败了,因为里面没有文件。对吗?
发布于 2018-08-14 19:27:35
与使用exec-maven-plugin相比,我建议您查看一下使用npm install构建节点源代码的frontend-maven-plugin。
使用这个插件,你不需要在你的机器上安装npm或node:这个插件自己管理,所以你不会遇到像command not found这样的问题。如下所示的配置应该可以工作:
<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>发布于 2019-09-19 23:27:30
我已经安装了节点,并将安装的文件夹移动到${project.baseUri}/ node /下。
这个错误现在已经解决了,我可以在命令提示符下使用下面的命令来执行npm安装。
c:\main\prjt\apphost_prjt>mvn frontend:npm发布于 2018-10-04 22:49:56
最后,我使用了前端maven-plugin
下面是pom.xml的摘录
<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>temp</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>
</configuration>
</execution>
<execution>
<id>prod</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run-script build</arguments>
</configuration>
<phase>generate-resources</phase>
</execution>
</executions>
</plugin>感谢您的回答
https://stackoverflow.com/questions/51840110
复制相似问题