Run maven commands via a Node JS API!
To create the maven handler, you need to call the create method providing the path to the POM file to be handled.
var mvn = require('node-maven-api').create('/workspace/project/pom.xml');
mvn.clean();
mvn.install();
Invoke a maven clean on your project.
mvn.clean();
Invoke a maven install on your project.
mvn.install();
Invoke a maven test on your project.
mvn.test();
Get the effective pom for your project. A promise will be returned which will be resolved to a javascript object which represents the xml effective pom.
var promise = mvn.effectivePom();
promise.then((result) => {
console.log('Effective POM is: ', result);
});
The API provided by this module can not possibly cover every maven goal, there is far too many! You can run any command you need with the execCommand function.
Function Parameters:
- The event name for your command.
- The command to execute.
// mvn clean install -f /path/to/my/pom.xml
mvn.execCommand('my-custom-event', 'clean install');
Sometimes you might want to perform some action after you have executed a maven command. Upon completion of a process, the api will trigger an event via the Node JS EventEmitter.
For the methods which this api exposes, the event names are as you may expect:
- clean
- clean-failed
- install
- install-failed
- test
- test-failed
- effective-pom
- effective-pom-failed
For custom commands you may provide your own event name, with the assumption that '-failed' will be automatically added in the event of a failure.
You may use the registerEvent
function to bind a callback to an event.
Function Parameters:
- The event name to bind a callback to.
- The callback to bind to the event.
Example:
mvn.registerEvent('my-custom-event', () => {
console.log('My Custom Maven command was successful! :)')
});
mvn.registerEvent('my-custom-event-failed', () => {
console.error('My Custom Maven command Failed... :(')
});
mvn.execCommand('my-custom-event', 'clean install');