?
Solved

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

Posted on 2003-03-20
11
Medium Priority
?
439 Views
Last Modified: 2010-03-31
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
Comment
Question by:ghigson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 3
11 Comments
 
LVL 9

Expert Comment

by:Ovi
ID: 8173605
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
 
LVL 35

Expert Comment

by:girionis
ID: 8173625
 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
 
LVL 35

Expert Comment

by:girionis
ID: 8173633
 Ahh... Ovi was faster :-)
0
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!

 
LVL 9

Expert Comment

by:Ovi
ID: 8173695
;-)
0
 

Author Comment

by:ghigson
ID: 8174024
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
 
LVL 35

Accepted Solution

by:
girionis earned 255 total points
ID: 8174150
 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
 

Author Comment

by:ghigson
ID: 8174257
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
 
LVL 9

Expert Comment

by:Ovi
ID: 8174447
"Perhaps the code from the book is expecting 2 more arguments, not fully described in your book."
0
 
LVL 35

Expert Comment

by:girionis
ID: 8174549
 Good point!! Is the example supposed to run or does it just try to show some basic principles of RMI?
0
 

Author Comment

by:ghigson
ID: 8186408
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
 
LVL 35

Expert Comment

by:girionis
ID: 8186768
 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month11 days, 18 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question