Node calls Java

Source: Internet
Author: User

The condition that node calls Java is the first node's running environment to install Java's JDK

Then you install the Java module in node

NPM Install Java

And then the node code.

Node calls Java's static method:

var java = require ("java");//Introduce Java module Java.classpath.push ("Xx.jar");// Import jar Package Java.classpath.push ("Xx.jar");//import jar package var str2= ' Hellow ';//define variable parameter var list = Java.callstaticmethodsync ("Com.demo.test", "Test", "str1", str2);//Call the Java method, the first parameter is the path where the package is located, the second parameter is the method name, The third and fourth parameters are the parameters of the method, without the///parameter, the third fourth parameter Console.log (list) is not passed;//The return value of the Print method

Node calls a non-static method:

varjava = require ("Java");//Introduction of Java Module Java.classpath.push ("Commons-lang3-3.1.jar");//import jar package Java.classpath.push ("Commons-io.jar");//import jar PackagevarList = Java.newinstancesync ("Java.util.ArrayList")///Load class is JS object Java.newinstance ("Java.util.ArrayList",function(err, list) {//Instance object List.addsync ("Item1");//Call Method List.addsync ("Item2");//Call Method});varArrayList = Java.import (' java.util.ArrayList ')); Get ObjectvarList =NewArrayList ();//Instantiate Object List.addsync (' item1 ');//Call method

Node calls Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.