node-java-maven icon indicating copy to clipboard operation
node-java-maven copied to clipboard

Usage example details required.

Open MrinaliniU opened this issue 6 years ago • 0 comments

Here is a sample code on how I'm trying to use "node-java-maven"

#!/usr/bin/env node

const java = require('java');
const mvn = require('node-java-maven');

java.asyncOptions = {
  asyncSuffix: undefined,    
  syncSuffix: "",   
  promiseSuffix: "Promise",  
  promisify: require('util').promisify 
};

mvn(function(err, mvnResults) {
  if (err) {
    return console.error('could not resolve maven dependencies', err);
  }
  mvnResults.classpath.forEach(function(c) {
    console.log('adding ' + c + ' to classpath');
    java.classpath.push(c);
  });


// My code to work with java jars goes here. Works fine!!


});

// But any usage of the java jars outside mvn() fails. !!!

The issue here is if I need to write unit/jest tests for my functions written within mvn() they would fail because the java dependencies are valid only within mvn(). I see that mvn() executes at the very end making it impossible to refer to the java jar imports anywhere outside mvn().

Can you please share the right way to use "Node-java-maven" so that the java.classpath pushed within mvn() is available globally?

MrinaliniU avatar Jun 14 '19 17:06 MrinaliniU