0

I have a php file which stores a Json string in a $result. I now have a java program which processes it and the main func returns a string array. Being new to java,Im not sure what argument to pass while creating a run configuration. And when i try to export the runnable jar(leaving the run config arguments empty), it says main method not found in the class. I feel its something to do with the argument passing, but im not sure how to do it. Sorry for this noob question. Here are my codes:

package jiraBurnDown;

public class JiraCurrentSprintBurnDownDataAttributes {

    public long _startTime = 0;
    public long _endTime = 0;
    public String sprintResponse;
    public String _statisticsField = "";
    public Map<String, JSONArray> _changes = new HashMap<String, JSONArray>();
    public Map<String, IssueState> _changesByIssue = new HashMap<String, IssueState>();

    public class IssueState {
        public boolean isInSprint = false;
        public Double estimatedWork = 0.0;

        public IssueState(boolean isInSprint, Double estimatedTime) {
            this.isInSprint = isInSprint;
            this.estimatedWork = estimatedTime;
        }

        public  String[] main(String sprintResponse) {

            String res[]=null;

            JSONObject obj = (JSONObject) JSONValue.parse(sprintResponse);
            if (obj != null) {
                //createEmptySeries();
                res=extractAllInfo(obj);
            }
            else
                System.out.println("Not Working ");
            return res;


        }

    }


    private String[] extractAllInfo(JSONObject obj) {
        String statisticField =extractStatisticsFieldName(obj);
        String time=extractStartAndEndTime(obj);
        String changes=extractChangesInfo(obj.get("changes"));
        String workData=extractAndSaveBaseLine(obj.get("workRateData"));
        String scopeChanges=extractAndSaveScopeChange();
        String[] info=new String[5];
        info[0]=statisticField;
        info[1]=time;
        info[2]=changes;
        info[3]=workData;
        info[4]=scopeChanges;

        return info;
    }

    private String extractStatisticsFieldName(JSONObject obj) {
        Object rawObj = obj.get("statisticField");

        if (rawObj != null && rawObj instanceof JSONObject) {
            _statisticsField = ((JSONObject) rawObj).get("name").toString();
            //addPoint(DataAttributes.DEFAULT_SERIES_NAME, _statisticsField);
        }
        return _statisticsField;

    }
//and other functions to process the JSON obj

and my php file is

    $result=curl_exec($ch);
    curl_close($ch);
    $result=json_decode($result, true);
    $result=json_encode($result);
    $out=shell_exec("java -jar /JiraInfo.jar $result");
    var_dump($out);
user3387677
  • 37
  • 2
  • 11

2 Answers2

0

I believe you need a main() method that is called to initialize your java Class. The JSON will then be passed in the args[] variable.

In addition I would quote the JSON string you're sending via CLI.

Dragony
  • 1,712
  • 11
  • 20
0

The main method in java should look like this

public static void main(String[] args){
}

the class that contains this method is called Main Class and because the main() method should be void, and in order to return result or output to your php, you can use System.out.print(), you will have to figure out an approach to pass array as result, (maybe format the result as JSON too)

for run configuariton you can mention the main class name in the command itself

$out=shell_exec("java -jar /JiraInfo.jar com.my.package.fooClass $result");

or set it in the manifest of JAR file.

Manifest-Version: 1.0
Created-By: 1.7.0_06 (Oracle Corporation)
Main-Class: com.my.package.fooClass
Yazan
  • 6,074
  • 1
  • 19
  • 33
  • i did it, and the manifest file shows the correct class. But nothing happens when i load the php page. Is there any way i can check if the obj is correctly being passed to the java code? – user3387677 Jun 26 '16 at 10:32
  • you can take it one step a time, ex, let the java app just return (system.out) the length of passed data, which can be read using `args[0]` inside `main()` if you get a correct length, then take next step... try also to add some logs to a file in the java app, that will help you trace the program – Yazan Jun 26 '16 at 10:40