Accessing a class at runtime

Discussion in 'Java' started by mike, May 18, 2010.

  1. mike

    mike Guest

    Hi,

    On the command line I can execute the following:

    java -jar eclipse.jar -application org.eclipse.StandAloneUpdate -
    command list

    I want to execute this from within a java program.
    I have added the eclipse.jar in my java program so that I can access
    the StandAloneUpdate class.
    How can I run execute the StandAloneUpdate class with the two commands
    ( -command list)?
    Use reflection or use system call using ProcessBuilder? All ideas are
    welcome.

    br,

    //mike
     
    mike, May 18, 2010
    #1
    1. Advertising

  2. mike

    Eric Sosman Guest

    On 5/18/2010 10:57 AM, mike wrote:
    > Hi,
    >
    > On the command line I can execute the following:
    >
    > java -jar eclipse.jar -application org.eclipse.StandAloneUpdate -
    > command list
    >
    > I want to execute this from within a java program.
    > I have added the eclipse.jar in my java program so that I can access
    > the StandAloneUpdate class.
    > How can I run execute the StandAloneUpdate class with the two commands
    > ( -command list)?
    > Use reflection or use system call using ProcessBuilder? All ideas are
    > welcome.


    Perhaps I've misunderstood your question, but what's wrong with

    org.eclipse.StandAloneUpdate.main(
    new String[] { "-command", "list" } );

    ?

    --
    Eric Sosman
    lid
     
    Eric Sosman, May 18, 2010
    #2
    1. Advertising

  3. mike

    Lew Guest

    mike wrote:
    >> On the command line I can execute the following:
    >>
    >> java -jar eclipse.jar -application org.eclipse.StandAloneUpdate -
    >> command list
    >>
    >> I want to execute this from within a java [sic] program.
    >> I have added the eclipse.jar in my java [sic] program so that I can access
    >> the StandAloneUpdate class.
    >> How can I run execute the StandAloneUpdate class with the two commands
    >> ( -command list)?
    >> Use reflection or use system call using ProcessBuilder? All ideas are
    >> welcome.


    Eric Sosman wrote:
    > Perhaps I've misunderstood your question, but what's wrong with
    >
    > org.eclipse.StandAloneUpdate.main(
    > new String[] { "-command", "list" } );
    >
    > ?


    or
    org.eclipse.StandAloneUpdate.main( "-command", "list" );

    --
    Lew
     
    Lew, May 18, 2010
    #3
  4. "Lew" <> wrote in message
    news:hsuiua$82f$...
    > mike wrote:
    >>> On the command line I can execute the following:
    >>>
    >>> java -jar eclipse.jar -application org.eclipse.StandAloneUpdate -
    >>> command list
    >>>
    >>> I want to execute this from within a java [sic] program.
    >>> I have added the eclipse.jar in my java [sic] program so that I can
    >>> access
    >>> the StandAloneUpdate class.
    >>> How can I run execute the StandAloneUpdate class with the two commands
    >>> ( -command list)?
    >>> Use reflection or use system call using ProcessBuilder? All ideas are
    >>> welcome.

    >
    > Eric Sosman wrote:
    >> Perhaps I've misunderstood your question, but what's wrong with
    >>
    >> org.eclipse.StandAloneUpdate.main(
    >> new String[] { "-command", "list" } );
    >>
    >> ?

    >
    > or
    > org.eclipse.StandAloneUpdate.main( "-command", "list" );
    >


    invalid number of arguments for method 'main'.
    cannot convert from String to String[].
    main has no matching definition for (String, String).
    ?...

    unless I am wrong ang someone does declare main as:
    public static void main(String... args);

    rather than:
    public static void main(String[] args);

    unless I have missed something here?...


    > --
    > Lew
     
    BGB / cr88192, May 21, 2010
    #4
  5. mike

    Arne Vajhøj Guest

    On 21-05-2010 10:16, BGB / cr88192 wrote:
    > "Lew"<> wrote in message
    > news:hsuiua$82f$...
    >> mike wrote:
    >>>> On the command line I can execute the following:
    >>>>
    >>>> java -jar eclipse.jar -application org.eclipse.StandAloneUpdate -
    >>>> command list
    >>>>
    >>>> I want to execute this from within a java [sic] program.
    >>>> I have added the eclipse.jar in my java [sic] program so that I can
    >>>> access
    >>>> the StandAloneUpdate class.
    >>>> How can I run execute the StandAloneUpdate class with the two commands
    >>>> ( -command list)?
    >>>> Use reflection or use system call using ProcessBuilder? All ideas are
    >>>> welcome.

    >>
    >> Eric Sosman wrote:
    >>> Perhaps I've misunderstood your question, but what's wrong with
    >>>
    >>> org.eclipse.StandAloneUpdate.main(
    >>> new String[] { "-command", "list" } );
    >>>
    >>> ?

    >>
    >> or
    >> org.eclipse.StandAloneUpdate.main( "-command", "list" );
    >>

    >
    > invalid number of arguments for method 'main'.
    > cannot convert from String to String[].
    > main has no matching definition for (String, String).
    > ?...
    >
    > unless I am wrong ang someone does declare main as:
    > public static void main(String... args);
    >
    > rather than:
    > public static void main(String[] args);
    >
    > unless I have missed something here?...


    Java since 1.5 allows both.

    To quote the JLS:

    <quote>
    The method main must be declared public, static, and void. It must
    accept a single argument that is an array of strings. This method can be
    declared as either

    public static void main(String[] args)

    or

    public static void main(String... args)
    </quote>

    Arne
     
    Arne Vajhøj, May 22, 2010
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ilyas
    Replies:
    1
    Views:
    319
    Softwaremaker
    Jul 4, 2003
  2. James D Carroll
    Replies:
    8
    Views:
    480
    Hemal Pandya
    Jun 27, 2004
  3. E11
    Replies:
    1
    Views:
    4,844
    Thomas Weidenfeller
    Oct 12, 2005
  4. Hal Vaughan
    Replies:
    11
    Views:
    1,155
    Gordon Beaton
    May 22, 2006
  5. Ami
    Replies:
    3
    Views:
    428
    Tomás
    Feb 27, 2006
Loading...

Share This Page