SSJS to call a method in java class (in java library)

前端 未结 1 761
一向
一向 2021-01-16 12:00

I\'ve created a java library (named: invoke) with a java class (Invoke). Its seen when expanding Script libraries under code in the designer navigation pane.

The cod

相关标签:
1条回答
  • 2021-01-16 12:42

    There are a number of things wrong, and as Fredrik mentions you should switch on the standard Error page.

    Your first code won't run because it is not correctly capturing the Exception. You are also using a main() method, which is normally used to execute a program. But you are calling it without any arguments. Avoid using that method unless it is for executing an application.

    So change it to this:

    package com.kkm.vijay;   
    
    import java.io.IOException;
    
    public class Invoke {
    
        public void mainCode() {
    
            Runtime r = Runtime.getRuntime();
            try {
                Process p = r.exec("C://WINDOWS//notepad.exe");
            } catch (IOException e) {
                e.printStackTrace();
            }
    
        }
    }
    

    You should put that code in the new Java view in Designer.

    Java view of image

    Next your button code needs to change.

    var v=new com.kkm.vijay.Invoke();
    v.mainCode();
    

    Testing that it should work fine. The issue next is, as it is SSJS the application will execute on the server. There may be security implications in this, and it may need you to modify the java.policy file in order to do this.

    The related permission will be java.io.FilePermission.

    0 讨论(0)
提交回复
热议问题