I want to execute shell commands from maven's pom.xml

I want to execute linux shell commands with maven. Here is what I tried:

<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>

But the above is not working. Can you please help me out.

-------------Problems Reply------------

Here's what's been working for me:

<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>

The problem here is that I don't know what is expected. With your current setup, invoking the plugin on the command line would just work:

$ 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] ------------------------------------------------------------------------
...

The global configuration is used, the hostname command is executed (laptop is my hostname). In other words, the plugin works as expected.

Now, if you want a plugin to get executed as part of the build, you have to bind a goal on a specific phase. For example, to bind it on compile:

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<id>some-execution</id>
<phase>compile</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>hostname</executable>
</configuration>
</plugin>

And then:

$ 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] ------------------------------------------------------------------------
...

Note that you can specify a configuration inside an execution.

Category:maven 2 Views:3 Time:2010-08-16
Tags: maven 2

Related post

  • Execute shell command from within MySQL client? 2009-05-30

    In oracle database, command "host" can be used to run bash command from database command window. Is there a equivalent command as "host" in mySql? --------------Solutions------------- You can use the system command. system command, \! command Execute

  • Executing shell commands using PHP, e.g. shell_exec() etc., on a remote host? 2010-09-19

    Is it possible to execute shell commands on a remote computer (not localhost)? For instance things like $output = shell_exec("unzip filename.zip"); You can assume that you have the login credentials of a user account on the remote machine, as well as

  • CTS_ERROR >>> Failed to execute shell command am instrument 2010-11-29

    Using the Android 2.2, API-8, SDK-r7 along with CTS-2.2_r4 suite. Updated the SDK_ROOT environment variable with SDK_r7 tools in “android-cts/tools/startcts” script and the “SDK_ROOT/tools” also included in PATH environment variable. Ran the “android

  • Executing shell command from ruby console returning Permission Denied Error? 2011-03-28

    Getting permission denied error while executing shell command from ruby console. And the same shell command is working from shell. From Shell.. [email protected]:~$ "`grep '^datadir=' /etc/mysql/my.cnf | cut -f 2 -d '='`/db_backups" bash: /db_b

  • How to execute shell command in C? 2011-05-12

    I am having problems executing the shell commands in C. I want to execute a shell command in C then capture the output of shell command and process the output further. I used following code to perform the functionality. But, the issue is when the she

  • How to execute shell commands in android? 2011-07-31

    I am trying to execute shell command through my code for adding entry in Iptables. The following is my piece of code private void createShellCommand(String uidValue_param, String interface_param) { // TODO Auto-generated method stub StringBuilder cmd

  • Execute shell command in c++ 2011-08-29

    I have a question regarding executing shell commands in c++. I'm building an application in winforms, vs 2008. My application has a button, when clicked should decode a binary file to a .csv file. I can decode files by first going to the right direct

  • python: os.system does not execute shell command 2012-03-02

    I need to execute shell command in python program (I have ubuntu). More specifically I want to create graph using graphviz in python script. My code is os.system("dot -Tpng graph.dot -o graph.png") It does not work, but if I just type "dot -Tpng grap

  • php executing shell command gives random output in only in heavy use mode 2012-03-28

    Please help me with this issue that I am facing on production server. I launched an application that saves images in a directory only after checking that it does not already exist. To check if it already exists I used the following command find $file

  • How to figure out the jars that the dependencies in the maven's pom.xml depend on? 2011-01-04

    I am very interested in how I can find out what are the jars that the dependences in the maven's pom.xml depend on. I am used to doing the adding of libraries (jars) myself in my web application project. I came across this need when I was trying to c

  • Where is the best place to specify maven repositories, pom.xml or settings.xml? 2010-02-08

    Where is the best place to specify required repositories for maven projects, pom.xml or settings.xml? What are the pros and cons of each location? What is best practice? It seems to me that defining the repositories in the POM is better for a number

  • Groovy executing shell commands 2008-10-01

    Groovy adds the execute method to String to make executing shells fairly easy; println "ls".execute().text but if an error happens, then there is no resulting output. Is there an easy way to get both the standard error and standard out? (other than c

  • Executing shell command from MySQL 2008-11-14

    I know what I'm looking for is probably a security hole, but since I managed to do it in Oracle and SQL Server, I'll give it a shot: I'm looking for a way to execute a shell command from a SQL script on MySQL. It is possible to create and use a new s

  • PHP exec() will not execute shell command when executed via browser 2009-02-11

    I have a certain PHP script that calls exec() to execute a command to convert a PDF to JPG. This command works fine in bash. To preempt your initial troubleshooting guesses, note the following: safe_mode = Off Permission on the directory containing t

  • vim: execute shell command without filtering 2009-08-06

    I want to select a block of text (eg. V%) and use the text as input to a shell command (eg. wc or pbcopy) - but I DON'T want to alter the current buffer - I just want to see the output of the command (if any) the continue editting without any changes

  • How to execute shell command in Javascript 2009-12-10

    I want to write a javascript function which will execute the system shell commands (ls for example) and return the value. How do I achieve this? --------------Solutions------------- What if the client you are executing this javascript is running Wind

  • Executing shell commands from Java 2010-06-17

    I'm trying to execute a shell command from a java application, on the GNU/Linux platform. The problem is that the script, that calls another java application, never ends, although it runs successfully from bash. I tried to debug it: (gdb) bt #0 0xb77

  • executing shell command in background from script 2010-09-10

    how can I execute a shell command in the background from within a bash script, if the command is in a string? For example: #!/bin/bash cmd="nohup mycommand"; other_cmd="nohup othercommand"; "$cmd &"; "$othercmd &"; this does not work -- how c

  • C# Web service: want to execute shell command as Admin (or higher priv.) 2010-12-08

    I have a web service which needs to execute a command on the server it's sitting on. Specifically, I'm running the "net start [certain service]" command. The problem lies in the permissions... the web service is running as NETWORK SERVICE, which does

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.128 (s). 11 q(s)