I have a project, in which I want to invoke another Jar file in M2 repo during the post execution phase of the current project.
Sample skeleton of my POM
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.1</version> <executions> <execution> <id>exec-one</id> <phase>verify</phase> <configuration> executable>java</executable> <arguments> <argument>-jar</argument> <argument>JarToInvoke.jar</argument> </arguments> <**workingDirectory**>/C:/path to repo</workingDirectory> </configuration> <goals> <goal>exec</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupId>GroupId of JarToInvoke</groupId> <artifactId>JarToInvoke</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> </dependencies> </plugin> </plugins>
I tried with maven-exec-plugin, but having the following issues;
-
Where I need to specify to JarToInvoke dependency ? As a project dependency or as a exec-plugin dependency ?
-
With hard coding the working directory(/C:/path to repo), I am able to invoke the JarToInvoke artifact. But it is not a good solution, because finally this project should run in any m/c with different OS’s. So how can I make the exec-plugin to search for the JarToInvoke artifact in the M2 repo of the project(default classpath) ?
3.While hard coding the M2 repo path in the working directory, I was able to invoke the JarToInvoke artifact. But while running the JarToInvoke artifact, it throws another dependency issue, some of the log4j dependencies to the JarToInvoke could not find. I made the JarToInvoke as a shaded jar and it work as expected. But it is not a permanent or good solution(Because the shaded jar size is of 35 MB). How can I instruct the exec-plugin to look for the dependent Jars in M2 repo.
Please share your suggestions. Thanks in Advance.
This example page from the Exec plugin’s documentation describes what you want I think.
If you could use the
exec:javagoal instead ofexec:exec, finding the JVM is taken care of for you. You can also pull in either plugin dependencies or project dependencies by changing theincludeProjectDependenciesandincludePluginDependenciesconfiguration options of the plugin.The only disadvantage is that you have to explicitly specify the main class in the JAR to run. You can look this up by opening up the manifest in the dependency JAR and read the Main-Class attribute.
If you really need to use
exec:exec, you could use the Maven Dependency Plugin’s copy-dependencies goal to copy dependencies from your local repository to a predefined location (such as${project.build.directory}/exec-jars) and then you can feed this directory in the exec plugin’sworkingDirectoryconfiguration option.