Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 448
  • Last Modified:

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 :

java -Djava.security.policy=administrator.policy
 -Djava.rmi.server.codebase=//hostname:port/
  com.deitel.messenger.rmi.server.ChatServerAdministrator
  start

Acc to http://java.sun.com/j2se/1.4.1/docs/tooldocs/windows/java.html  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 http://java.sun.com/j2se/1.4.1/docs/tooldocs/windows/java.html 
(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 !

Regards

Graeme Higson
0
ghigson
Asked:
ghigson
  • 5
  • 3
  • 3
1 Solution
 
OviCommented:
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.
0
 
girionisCommented:
 You are missing something here. The parameters passed with the -D option (i.e. java.security.policy 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.
0
 
girionisCommented:
 Ahh... Ovi was faster :-)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
OviCommented:
;-)
0
 
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 ?    

GH


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

java -Djava.security.policy=administrator.policy
-Djava.rmi.server.codebase=//hostname:port/
 com.deitel.messenger.rmi.server.ChatServerAdministrator
 start administrator.policy //hostname:port/
0
 
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.  
0
 
OviCommented:
"Perhaps the code from the book is expecting 2 more arguments, not fully described in your book."
0
 
girionisCommented:
 Good point!! Is the example supposed to run or does it just try to show some basic principles of RMI?
0
 
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 ...
0
 
girionisCommented:
 Thank you ghigson I am glad I helped, although Ovi deserves some points as well. Ovi I will post a question for you :-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now