This is our first Java callout-enabled API proxy. For our other APIs, we are using the Apigee grunt deployment tool: https://github.com/apigeecs/apigee-deploy-grunt-plugin/blob/master/Gruntfile.js
We are attempting to compile using it, so we've enabled the javac step in the file. This is the command:
javac java/src/com/<our-company>/ecommerce/<vendor-tool>/executor/*.java java/src/com/<our-company>/ecommerce/<vendor-tool>/util/*.java -d ./target/java/bin -cp /c/Git/<our-api>/java/lib/expressions-1.0.0.jar:/c/Git/<our-api>/java/lib/message-flow-1.0.0.jar -verbose
which works when running on the command line. However, when running it using Grunt, the classpath doesn't seem to get picked up and the necessary Apigee classes are coming back as not being found. Is this a discrepancy between how the Grunt shell processing works?
Here is the entry we have in Gruntfile.js:
javaCompile: { command: 'javac java/src/com/<our-company>/ecommerce/<vendor-tool>/executor/*.java java/src/com/<our-company>/ecommerce/<vendor-tool>/util/*.java -d ./target/java/bin -cp /C/Git/<our-api>/java/lib/expressions-1.0.0.jar:/C/Git/<our-api>/java/lib/message-flow-1.0.0.jar -verbose' }
@Diego Zuluaga, might you have a suggestion on this one?
Answer by Sean Case · Mar 28, 2016 at 12:24 PM
Ok, I think I've found a solution. It appears that grunt-chalk (which is used by grunt-shell) is setting the terminal type based on platform. I was able to use it's line:
process.platform === 'win32' && !/^xterm/i.test(process.env.TERM)
along with a function within the grunt shell command to create a test and conditional build:
shell: { options: { stderr: false, failOnError: true }, javaCompile: { command: function () { if (process.platform === 'win32') { return 'javac -source 1.7 -target 1.7 java/src/com/<path to source>/*.java java/src/<path to source>/*.java -cp %cd%\java\lib\expressions-1.0.0.jar;%cd%\java\lib\message-flow-1.0.0.jar -d target/java/bin -verbose'; } else { return 'javac -source 1.7 -target 1.7 java/src/com/<path to source>/*.java java/src/<path to source>/*.java -cp ${PWD}/java/lib/expressions-1.0.0.jar:${PWD}/java/lib/message-flow-1.0.0.jar -d ./target/java/bin -verbose'; } } }, javaJar : { command: 'jar cvf target/apiproxy/resources/java/BuildReviewURL.jar target/java/*' } }
which seems to work.
I didn't have much time to investigate further, but was also hopeful that perhaps utilizing grunt-run-java (https://www.npmjs.com/package/grunt-run-java) may have been an opportunity to resolve this, too.
Thanks for the assistance!