I am developing a node.js application where I need to execute java code.
I am using de node-jre module (https://www.npmjs.com/package/node-jre).
The example in this web (Hello.class) is running correctly with this code and compilling de Hello class by console with javac Hello.java:
var output = jre.spawnSync( // call synchronously
['java'], // add the relative directory 'java' to the class-path
'Hello', // call main routine in class 'Hello'
['World'], // pass 'World' as only parameter
{ encoding: 'utf8' } // encode output as string
).stdout.trim();
The problem is when I tried to execute my java project (developed with eclipse). The documentation say that in this directory 'java' search inside jar files. So, it was the first thing I tried: to export the proyect to jar, but it does not work.
So, how can I execute a complete project (with only one main class)?, I think it is important to say that the project use external libraries.
The META-INF/MANIFEST.MF inside jar looks like:
Manifest-Version: 1.0
Class-Path: .
Main-Class: com.packagename.example1.ClassName
Name: org/apache/oro
Specification-Title: Jakarta ORO
Implementation-Title: org.apache.oro
Implementation-Version: 2.0.8 2003-12-28 11:00:13
Specification-Version: 2.0.8
Specification-Vendor: Apache Software Foundation
Implementation-Vendor: Apache Software Foundation
So, my code is:
var output = jre.spawnSync( // call synchronously
['java'], // add the relative directory 'java' to the class-path
'ClassName', // call main routine in class 'Hello'
['World'], // pass 'World' as only parameter
{ encoding: 'utf8' } // encode output as string
).stdout.trim();
And I tried also with:
var output = jre.spawnSync( // call synchronously
['java'], // add the relative directory 'java' to the class-path
'com.packagename.example1.ClassName', // call main routine in class 'Hello'
['World'], // pass 'World' as only parameter
{ encoding: 'utf8' } // encode output as string
).stdout.trim();
'java' was the folder that I have in node in the same level that server.js
Manifest-Version: 1.0 Class-Path: . Main-Class: com.package.example1.ClassName