开发者

How to inherit the current path when invoking Maven's exec-maven-plugin?

I have an <exec-maven-plugin> which calls an external command (in this case, svnversion). The command is in the path for the current user.

However, when a separate shell is spawned by the plugin, the path is not initialized. I don't want to hardcode or define a variable for each external command (there would be too much to maintain, especially that there are both Windows and *nix users).

My pom.xml contains the following:

  <plugin>
 <groupId>org.codehaus.mojo</groupId>
 <artifactId>exec-maven-plugin</artifactId>
 <version>1开发者_如何学运维.1</version>
 <executions>
  <execution>
   <id>svnversion-exec</id>
   <phase>process-resources</phase>
   <goals>
    <goal>exec</goal>
   </goals>
   <configuration>
    <executable>svnversion</executable>
    <arguments>
     <argument><![CDATA[ >version.txt ]]></argument>
    </arguments>
   </configuration>
  </execution>
 </executions>
  </plugin>

Currently I get the following output:

[INFO] [exec:exec {execution: svnversion-exec}] 'svnversion' is not recognized as an internal or external command, operable program or batch file.

[ERROR] BUILD ERROR: Result of cmd.exe /X /C "svnversion >version.txt" execution is: '1'.

Thank you!


That's weird because as written in the documentation, the executable parameter is not necessarily the full path to an executable:

The executable. Can be a full path or a the name executable. In the latter case, the executable must be in the PATH for the execution to work.

And on my machine (where svnversion is in /usr/bin/ which is in the PATH), the configuration you posted just works (I used the exact same snippet):

$ mvn process-resources
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Q2821100
[INFO]    task-segment: [process-resources]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources {execution: default-resources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/pascal/Projects/stackoverflow/Q2821100/src/main/resources
[INFO] [exec:exec {execution: svnversion-exec}]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5 seconds
[INFO] Finished at: Wed May 12 21:30:35 CEST 2010
[INFO] Final Memory: 7M/87M
[INFO] ------------------------------------------------------------------------
$ cat version.txt 
exported

Maybe double check the PATH of the user that is running maven. Also, why do you say that a shell is spawned? Who is spawning that shell?


I read this:

The plugin will search for the executable in the following order:

  • relative to the root of the project
  • as toolchain executable
  • relative to the working directory (Windows only)
  • relative to the directories specified in the system property PATH (Windows Only)

Otherwise use the executable as is.

So "Windows Only" !

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜