Can the Java application launcher pass arguments with the -D option ?

Hello All,

I am a java beginner/intermediate, and am reading through the book "Advanced Java 2 Platform - How to Program - 1st Ed", by Deitel.

I am reading through Chapter 13 on RMI callbacks and the DeitelMessenger example which uses RMI between server and client.

MY QUESTION is to do with the syntax for passing in arguments with the java application launcher.

On page 837 the book says to enter the following on the command line, to start class ChatServerAdministrator. The text (A) is :


Acc to  any args to be passed to the main method should be listed AFTER the class name.  I dont see specified here any other way. So acc to 
(A) defines/sets  2 properties with the 2 -D options relating to policy files, and  passes ONE argument, value "start",  to the main method of class ChatServerAdministrator

BUT the source code ChatServerAdministrator  in the Deitel book (not repeated here) is clear that it expects THREE arguments to be passed. ( If arg[0] has value "start", then arg[1] and arg[2] are passed to Strings policy and codebase respectively).

So whats happening ?
1)  Where are the other 2 args AFTER the class name - as required by the java app launcher syntax ?
2)  Are the other 2 args somehow passed in from the two -D options ? If so how ?  And where is this explained on the sun website docs. Note, the 2nd and 3rd expected args seem to be related to the above -D option policy files.
3)  Is the above text (A) in the book wrong ?

Many thanks in advance to anyone who can help shed some light !


Graeme Higson
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Since -D option is used for setting properties to be acesible to the JVM and application respectively, those are not passed as arguments to the main method. Even if so, the argument start should be on position 2 and not 0 in the args array. Perhaps the code from the book is expecting 2 more arguments, not fully described in your book.
 You are missing something here. The parameters passed with the -D option (i.e. and java.rmi.server.codebase) are not passed to the main method but to the VM. Similarly the third parameter which is the class name (com.deitel.messenger.rmi.server.ChatServerAdministrator) is passed to the VM as well. Then the parameter after the classname (which is the "start" word) is passed to the main method.

  Hope this clarifies things.
 Ahh... Ovi was faster :-)
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

ghigsonAuthor Commented:
Thankyou girionis and ovi. Just to clarify the source code :

In the main method :
     // start server with user-provided policy, codebase
     // and Registry hostname
     if ( args[ 0 ].equals( "start" ) )
         startServer( args[ 1 ], args[ 2 ] );
where method startServer starts as follows :

  // set up activatable server object
    private static void startServer( String policy,
      String codebase ) throws Exception
   {  ....  }

 So the program is expecting :

args[ 0 ] = String start_stop (above value "start")
args[ 1 ] = String policy
args[ 2 ] = String codebase

Whereas the java app launcher commmand line, specified in the book just has ONE argument, value "start", AFTER the class argument ChatServerAdministrator.

So if you say arguments are ONLY passed to the main method if they are listed on the java command line AFTER the class name, then this is what I thought.

So do we conclude that the above java command text is wrong, its missing the 2nd and 3rd args Strings policy and codebase ?    


 It's obviously missing soem values then. Try to do this and tell us what happens:

 start administrator.policy //hostname:port/

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ghigsonAuthor Commented:
Ok, I'll do that - It makes sense. Unfortunately I won't be able to try it out for a few days or more, so I let you know then.  
"Perhaps the code from the book is expecting 2 more arguments, not fully described in your book."
 Good point!! Is the example supposed to run or does it just try to show some basic principles of RMI?
ghigsonAuthor Commented:
Ok, got my PC up and running again. Everything is reacting as it should, acc to you 2 chaps
 and sun/.../java.exe - that is - it needs the full 3 args after the class name,
irrespective of the -D properties setting. So thanks to U 2.

Also the code in the book "Advanced Java 2 Platform - How to Program - 1st Ed",
by Deitel, Deitel,Santry - SHOULD be able to be run - This is one thing it prides itself on ...
 Thank you ghigson I am glad I helped, although Ovi deserves some points as well. Ovi I will post a question for you :-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.