facebook

Invoking Main method of Main.class

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #255946 Reply

    cpwynn
    Member

    Please help…

    Im trying to invoke the public static main method of the class Main which calls a number of other methods, etc. etc….. and pass it the arguments…. the Main.class is not the main that I want to call to start the program…

    Do I just need to instantiate the class and it will call the main method of the main class???

    Here’s some of my code and how i tried to do it:

    
    
    import com.sap.tc.jtools.*;
    import com.sap.tc.jtools.jlint.*;
    import com.sap.tc.jtools.jlint.Main;
    .
    .
    .
    public class myClass{
    .
    .
    .
    public static void main(String[] args) {
    
    .
    .
    .
    }
    .
    .
    .
    public static void runTests(){
    
    com.sap.tc.jtools.jlint.Main jMain = new com.sap.tc.jtools.jlint.Main();
            
            Class[] argTypes = new Class[1];
            argTypes[0] = String[].class;
            
            try {
              Class cl = Class.forName("Main");
              //Method mainMethod=cl.getMethod("Main",argTypes);
              Method mainMethod = cl.getDeclaredMethod("main",argTypes);
              Object[] argListForInvokedMain = new Object[1];
              argListForInvokedMain[0] = new String[0];
              //Arguments go here...
              mainMethod.invoke(null,argListForInvokedMain);
              }
              catch (ClassNotFoundException ex) {
                System.err.println("Class Main not found in classpath.");
              }
    }
    }
    
    

    The above code is my class… and I’m trying to call another class (Main.class) and invoke its main method…. that class is:

    
    package com.sap.tc.jtools.jlint;
    .
    .
    .
    public class Main
    {
    
        public Main()
        {
        }
    
        public static void main(String args[])  //this is what i want to run/INVOKE!!!
        {
            if(args.length != 2)
            {
                printHelp();
                System.exit(1);
            }
            File configFile = new File(args[0]);
            File requestFile = new File(args[1]);
            run(configFile, requestFile);
            System.out.println("Done.....");
        }
    .
    .
    .
    

    Please help… thanks!!!

    #255958 Reply

    Riyad Kalla
    Member

    What exception are you getting? Try actualy creating a string[] as the arg list, don’t make a object[].

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: Invoking Main method of Main.class

You must be logged in to post in the forum log in