Accessing a class at runtime

M

mike

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
 
E

Eric Sosman

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" } );

?
 
L

Lew

mike said:
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 said:
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" );
 
B

BGB / cr88192

Lew said:
mike said:
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 said:
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?...

 
A

Arne Vajhøj

Lew said:
mike said:
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 said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top