Mule could not resolve placeholder with maven exec - maven

I'm using maven exec plugin to run Mule 3. I have some properties that are correctly resolved when they are in my properties file, however if I try to provide them as a JVM option they do not get resolved/overridden. Below is my maven exec config:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>org.mule.MuleServer</mainClass>
<arguments>
<argument>-config</argument>
<argument>src/main/app/prioritisation-api.xml</argument>
<argument>-classpath</argument>
<argument>src/main/app</argument>
<argument>-Dmule3.http.root=http://localhost:8095</argument>
</arguments>
<classpathScope>compile</classpathScope>
</configuration>
</plugin>
I also tried using -M-Dmule3.http.root=http://localhost:8095 but that did not work.

The exec plugin has two goals java and exec. You are using the java which means:
(Excerpt from the docs):
exec:java Executes the supplied java class in the current VM with the
enclosing project's dependencies as classpath.
I would suggest to use the exec goals instead and start a separate JVM to which you can provided different parameters.

Related

Maven executing configured plugin

Under Maven version 3.0.4 I have the problem to specify the execution of a single configured plugin. Say I have two different configured maven-antrun-plugins. Both are in the same lifecycle. How can I target the plugin I want to execute without using different lifecycles?
Since version 3.3.1 it's possible to do it in this form: mvn groupid:artifactid:goal#id
Is there a way to do this in a similar way in version 3.0.4 or lower?
You can use the "default-" in your pom to have the first plugin running during the default lifecycle (since Maven 2.2.0), and use a classifier for the second plugin, for example with the maven jar plugin, you can see the example below:
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>default-jar</id>
<configuration>
<excludes>
<exclude>**/somepackage/*</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>special-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<includes>
<include>**/sompackage/*</include>
</includes>
<classifier>somepackage</classifier>
</configuration>
</execution>
</executions>
</plugin>

executing shell script and ant script with named parameter using maven

I am implementing maven wrapper to ant builds. And the ant command used to build the project is as follows
ant -v -f build.xml -Darch=linux-java7 -Dconfig=/work/build.config -Doutput=/work/bldout/
Now i have to execute the above command through maven . I tried to implement this using "I want to execute shell commands from maven's pom.xml" and "http://sanchitbahal.wordpress.com/2011/09/19/maven-exec-plugin-vs-maven-antrun-plugin-for-running-command-line-tool/"
The sample code i tried inside my pom.xml is as follows :
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<executions>
<execution>
<id>execute-shell</id>
<phase>compile</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>test.sh</executable>
<arguments>
<argument>ARG1</argument>
<argument>ARG2</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
But i am not able to figure out how to pass named parameter such as "-Darch=linux-java7" as arguement to build.xml
Also used maven-antrun plugin to invoke build.xml as follows :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>run-target</id>
<phase>install</phase>
<configuration>
<target>
<ant antfile="build.xml" target="all" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
But here also i am unable to figure out how to pass parameter such as "-Darch=linux-java7" as arguement to build.xml
What i know is that i can put the command in a shell script(in a .sh file) and call the shell script using maven-exec-plugin , but wanted to know if it is possible to do without doing so .
Use antrun, it has less external dependencies (like ant executable on path etc.)
Ant tasks executed by antrun plugin inherit all properties defined inside the properties section of your pom.
So you simple need to include:
<properties>
<arch>linux-java7</arch>
...
</properties>
inside your pom to make it work.

Running adb.exe command from maven 3.0.5

Is it possible to run adb.exe commands from maven. For example I want to run adb shell instrument -e classname#testcasename -w packagename/instrumenation. I need to run this command in maven is it possible?? Do i need to specify it in the pom.xml file or it can be run directly by specifying the command-line argument.
You can use the Maven Exec Plugin to execute cmd commands.
In the snippet below (add it to a pom.xml), the command ping with the argument 8.8.8.8 will be executed every time you do a mvn install:
<project>
...
<build>
<plugins>
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<version>1.2.1</version>
<executions>
<execution>
<id>My Command Runner</id>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>ping</executable>
<arguments>
<argument>8.8.8.8</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>
In your case, the inner configuration would be something around:
<configuration>
<executable>adb </executable>
<arguments>
<argument>shell</argument>
<argument>instrument</argument>
<argument>-e</argument>
<argument>classname#testcasename</argument>
<argument>-w</argument>
<argument>packagename/instrumenation</argument>
</arguments>
</configuration>
Make sure you bind it to the phase you really need. The example above, as said, is bound to the mvn install - meaning the command will be executed when someone runs that (install) phase.

Executing cmd command using Maven

I want to execute this command:
zipalign [-f] [-v] <alignment> infile.apk outfile.apk
Using Maven. I have to execute this command in the Android SDK/ tools directory. Can anyone help me on how to do this? I think this can be done using batch file but I am not sure how to create a batch file. I need this command to be executed when I type "mvn clean install". Thanks
Executing commands using Maven
You can use the Maven Exec Plugin bound to the install phase.
In the snippet below, the commant ping with the argument 8.8.8.8 will be executed every time you do a mvn install:
<project>
...
<build>
<plugins>
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<version>1.2.1</version>
<executions>
<execution>
<id>My Command Runner</id>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>ping</executable>
<arguments>
<argument>8.8.8.8</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>
 
And that's it.
 
 
Update:
I see now what you really having trouble with is executing zipalign, not an arbitrary command. For that, there are two ways.
Using the built-in zipalign of the maven-android-plugin
As of release 2.5.0 of the Android Maven Plugin the zipalign goal is part of the plugin. To activate simply add the goal zipalign as an execution (e.g. to the package phase) and set the skip parameter in the plugin configuration to false:
<zipalign><skip>false</skip></zipalign>
Full <plugin> tag example:
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>maven-android-plugin</artifactId>
<inherited>true</inherited>
<configuration>
<sign>
<debug>false</debug>
</sign>
<zipalign>
<verbose>true</verbose>
<inputApk>${project.build.directory}/${project.artifactId}.apk</inputApk>
<outputApk>${project.build.directory}/${project.artifactId}-signed-aligned.apk
</outputApk>
</zipalign>
</configuration>
<executions>
<execution>
<id>alignApk</id>
<phase>package</phase>
<goals>
<goal>zipalign</goal>
</goals>
</execution>
</executions>
</plugin>
Sources:
Here you'll find an example using the an older version (still called android-maven-plugin);
ZipalignAPKBuiltByMAven: Describes how to automatically zipalign an APK that has been built by Maven.
Simpligility: Maven Android Plugin with zipalign and improved verification
Another example: A full pom.xml that uses the zipalign.
Zipalign using Exec-Maven Plugin
The code below will bind the functionality of zip aligning to the package phase, overwriting previous zip aligned file without asking.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<id>zipalign</id>
<goals>
<goal>exec</goal>
</goals>
<phase>package</phase>
<configuration>
<executable>${ANDROID_HOME}/tools/zipalign</executable>
<arguments>
<argument>-f</argument>
<argument>4</argument>
<argument>target/${project.build.finalName}.apk</argument>
<argument>target/${project.build.finalName}-zipped.apk</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
Please note that this profile has to be added to the pom for the actual APK. You can't add it to a parent pom. The reason for this is that it uses the Maven property that defines the artefact name (project.build.finalName).
If you're building an Android project with Maven, you should be using the maven-android-plugn, which supports the zipalign tool directly.

run java server from maven

I need to run a server(implemented in a Java class) from Maven but if I use the exec:java goal, it will block maven and it will not pass to next phases which connect to the server.
Is there any way to run the exec:java task asynchronously, without interrupting the maven execution?
Thanks!
You could use exec-maven-plugin to run shell script which would start your process and detach from it (letting process to run in background). Something like this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>start-server</id>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>src/test/scripts/run.sh</executable>
<arguments>
<argument>{server.home}/bin/server</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
Where run.sh could be like this (for U*nix platform):
#! /bin/sh
$* > /dev/null 2>&1 &
exit 0
That should do the trick.
It looks like you can do this with the antrun plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
<configuration>
<tasks>
<java fork="true" spawn="true" classpathref="maven.runtime.classpath" className="fully.qualified.package.App"/>
</tasks>
</configuration>
</plugin>
If you're running this server class in order to run further integration testing steps in your Maven POM, then it's actually better to consider using a Continuous Integration tool such as Jenkins, it has a lot of Plugins that allows you to run your own classes, start and stop servers, deploy applications, and many other possibilities, and it's free.

Resources