Maven 2 我想从Maven';s pom.xml
我想用Maven执行Linux shell命令。以下是我尝试过的:Maven 2 我想从Maven';s pom.xml,maven-2,Maven 2,我想用Maven执行Linux shell命令。以下是我尝试过的: <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.1.1</version> <executions> <execution>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>hostname</executable>
</configuration>
</plugin>
org.codehaus.mojo
execmaven插件
1.1.1
执行官
主机名
以下是我一直在做的事情:
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<executions>
<execution><!-- Run our version calculation script -->
<id>Version Calculation</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${basedir}/scripts/calculate-version.sh</executable>
</configuration>
</execution>
</executions>
</plugin>
execmaven插件
org.codehaus.mojo
版本计算
生成源
执行官
${basedir}/scripts/calculate-version.sh
这里的问题是我不知道什么是期望的。在当前设置下,在命令行上调用插件即可: $ mvn exec:exec [INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [INFO] Building Q3491937 [INFO] task-segment: [exec:exec] [INFO] ------------------------------------------------------------------------ [INFO] [exec:exec {execution: default-cli}] [INFO] laptop [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ ... 然后: $ mvn compile [INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [INFO] Building Q3491937 [INFO] task-segment: [compile] [INFO] ------------------------------------------------------------------------ [INFO] [resources:resources {execution: default-resources}] [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] skip non existing resourceDirectory /home/pascal/Projects/Q3491937/src/main/resources [INFO] [compiler:compile {execution: default-compile}] [INFO] Nothing to compile - all classes are up to date [INFO] [exec:exec {execution: some-execution}] [INFO] laptop [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ ... $mvn编译 [信息]正在扫描项目。。。 [信息]------------------------------------------------------------------------ [信息]Q3491937号楼 [信息]任务段:[编译] [信息]------------------------------------------------------------------------ [信息][资源:资源{执行:默认资源}] [信息]使用“UTF-8”编码复制筛选的资源。 [信息]跳过不存在的resourceDirectory/home/pascal/Projects/Q3491937/src/main/resources [信息][编译器:编译{执行:默认编译}] [信息]无需编译-所有类都是最新的 [INFO][exec:exec{execution:some execution}] [信息]笔记本电脑 [信息]------------------------------------------------------------------------ [信息]构建成功 [信息]------------------------------------------------------------------------ ...
请注意,您可以在
执行中指定配置。问题是,可执行文件在Linux中以不同的方式工作。如果要运行.sh
文件,应将添加到pom.xml
文件的
部分
execmaven插件
3.0.0
org.codehaus.mojo
重命名生成工件
包裹
执行官
猛击
handleResultJars.sh
2选项:
你想从maven执行一个命令而不绑定到任何阶段,你只需键入命令并由maven运行它,你只想让maven运行一些东西,你不在乎我们是否在编译/包/。。。假设我想用maven运行npm start
,您可以通过以下方法实现:
mvn exec:exec-Pstart节点
为此,您需要下面的maven部分
<profiles>
<profile>
<id>start-node</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.2</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>npm</executable>
<arguments><argument>start</argument></arguments>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
谢谢!汤姆·本·大卫。它帮助了我。当我在演示文件夹中进行pip安装时,正如您提到的npm安装
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.2</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>pip</executable>
<arguments><argument>install</argument></arguments>
<workingDirectory>${project.build.directory}/Demo</workingDirectory>
</configuration>
org.codehaus.mojo
execmaven插件
1.3.2
执行官
皮普
安装
${project.build.directory}/Demo
这对我也很有效。后来,我切换到maven-antrun插件
,以避免在Eclipse中出现警告。如果可能的话,我更喜欢使用默认插件。例如:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>get-the-hostname</id>
<phase>package</phase>
<configuration>
<target>
<exec executable="bash">
<arg value="-c"/>
<arg value="hostname"/>
</exec>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
maven antrun插件
3.0.0
获取主机名
包裹
跑
请清理您的问题并格式化问题中的pom.xml。它不可读。我不是故意粗鲁,但你真的需要学习如何提问,我们不是通灵者。你做了什么?你得到了什么?预期的结果是什么?无意冒犯@PascalThivent,但是那些了解Maven和pom.xml的人知道OP指的是什么。:)因此,如果有人不知道Maven或pom.xml,那么他们可能应该跳过这个问题。这对我来说是很明显的,可能很多人都喜欢这个问题。[ERROR]BUILD ERROR[INFO]---------------------------------------------------------------[INFO]在插件“exec maven plugin”的定义中,一个或多个必需的插件参数对于“exec:exec”[0]无效/缺失。请指定以下内容:。。。VALUE-或-在命令行上,指定:'-Dexec.executable=VALUE'我现在得到这个错误。@gnash-85:我仍然不知道你在做什么。我使用了您提供的代码片段,没有问题,如上所示。请更新您的问题,以显示您如何调用maven(以及如果您更改了某些内容,您当前的配置是什么)。我正在尝试从父pom.xml执行mvn exec:exec。我得到了这个错误。但当我单独执行它时,它就起作用了。@gnash-85:这很正常。在父级上调用mvn exec:exec
时,mvn将在多模块构建的所有项目上运行它,包括父级。但是父pom没有任何插件的配置,该插件需要定义可执行文件
,因此会出现错误消息。如果在执行
块中指定配置
,如果作为组的一部分运行(mvn安装
),它将工作,但抛出指定以下内容:
如果直接使用mvn exec:exec运行,则会出错。我想补充一点,这不适用于(至少)插件的1.5.0版,因为
应该跟在
后面,而不是放在里面。我花了很长时间才发现这个简单的语法错误。Maven的错误输出真的没有那么大帮助。如果我们想在部署阶段后运行脚本,我们需要提供什么阶段或目标??Maven阶段列在这里:在配置块中使用${basedir}/scripts/
,而不是在
中给出完整路径也可能是一个好主意!对于我这个喜欢shell脚本的Windows用户来说,这是关键!表格中的一个小错误
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.2</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>pip</executable>
<arguments><argument>install</argument></arguments>
<workingDirectory>${project.build.directory}/Demo</workingDirectory>
</configuration>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>get-the-hostname</id>
<phase>package</phase>
<configuration>
<target>
<exec executable="bash">
<arg value="-c"/>
<arg value="hostname"/>
</exec>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>