Is there a way for maven to trigger system command after successful or unsuccessful build?
Right now I'm using external script to run mvn package
, but I would like this feature integrated with maven process.
Asked
Active
Viewed 158 times
1

wlk
- 5,695
- 6
- 54
- 72
-
You know that mvn package include all previous life-cycle phases...so what did you run before the mvn package ? – khmarbaise Apr 13 '11 at 13:06
-
I'm using only `mvn package`, external script is used to for example copy files to server. – wlk Apr 13 '11 at 13:09
-
External server means production/test? – khmarbaise Apr 13 '11 at 13:21
-
Both, there are few different scripts, now I would like to rethink and rebuild this system. – wlk Apr 13 '11 at 13:25
-
If you like to go to production mvn package is wrong. You should use mvn release:prepare release:perform and then use the artifacts which are stored in the Repo Manager. – khmarbaise Apr 13 '11 at 13:34
-
OK, thanks, what about copying packaged jar to test servers? – wlk Apr 13 '11 at 13:41
-
Why would you like to copy jar files? Aren't you using war/ear files ? Furthermore you can use the maven-wagon-plugin to transfer files to a server...but this not the focus of Maven. Better write a command line app with the Help of Aether Lib (Access Maven Repositories) ... – khmarbaise Apr 13 '11 at 13:43
-
This is simple jar written in Java SE, but it's running on servers. I'll check out this plugin you mentioned. – wlk Apr 13 '11 at 13:46
-
On which kind of server? – khmarbaise Apr 13 '11 at 13:48
-
Linux - Debian. But it's a standalone app that's doing some calculations and produces output files. – wlk Apr 13 '11 at 13:52
-
You mean the simple jar you mentioned is a command line app ? – khmarbaise Apr 13 '11 at 14:12
-
Why don't you use 'mvn deploy' and use Maven deploy plugin to copy the jars using ftp? http://maven.apache.org/plugins/maven-deploy-plugin/examples/deploy-ftp.html – Prabhjot Apr 13 '11 at 14:41
-
Yes, it's a command line app. – wlk Apr 13 '11 at 14:45
1 Answers
0
Maven supports pre and post scripts. See the accepted answer here. In your case it would be mavenrc_post.bat
You can easily do that by creating a file at /etc/mavenrc or ~/.mavenrc (Linux) or %HOME%\mavenrc_pre.bat (Windows) Maven executes those on startup if they exist unless you've defined a variable named MAVEN_SKIP_RC.