SCOUG-Programming Mailing List Archives
Return to [ 19 |
August |
1998 ]
Content Type: text/plain
From Peter Skye:
I got a private email from Terry Warren which answered one of my posted
questions, and it's worth passing along to everyone.
I had asked how we'd be starting the ftp server once it's finished:
> > > > > 1. How, exactly, do you start this thing once it's written?
And Rollin had responded:
> > > > Probably something like:
> > > >
> > > > java FtpServer 21
> > > >
> > > > Where 21 is the port to listen to.
So I asked:
> > > Why are we putting the port on the command line? Why not in a setup
> > > file where it will join other things such as the user profile
> > > filename?
Terry, the most knowledgeable Java programmer I know, answered me
privately with the following:
> > ... one standard way
> > of dealing with these types of values is to use the system properties
> > object. It is similar to passing by command line (and in fact you can
> > pass them this way also) but is a little more flexible and can be
> > (more easily) adapted to persistent properties.
> >
> > The way it works is:
> >
> > (1) if you pass any command line switch defined with -D the jvm adds it
> > to the system properties array for your application.
> >
> > (2) the application can then access it using the System.getProperty()
> > method.
> >
> > (3) the properties can also be set by another program running in the
> > same jvm.
> >
> > so, in your example, you might pass the property as something like:
> >
> > java -Dscoug.ftpport=21 ftpserver
> > (you MUST put the switch before the program name)
> >
> > and in the program you would have code like:
> >
> > String ftpport = System.getProperty("scoug.ftpport", "21");
> > // the second parm is the default to be used if the property
> > is not defined
> >
> > or:
> >
> > int ftpport = Integer.parseInt(System.getProperty("scoug.ftpport",
> > "21"));
> >
> > Ideally, this code would be part of a startup class that could also
> > reference an existing serialized Property object containing other
> > configuration data; this is a better approach for persistent
> > properties.
> >
> > (I can supply a class of this type if needed).
Terry, thank you very much. I didn't know this capability was
available.
I now need to study the system properties object and system properties
array.
- Peter Skye
=====================================================
To unsubscribe from this list, send an email message
to "steward@scoug.com". In the body of the message,
put the command "unsubscribe scoug-programming".
For problems, contact the list owner at
"rollin@scoug.com".
=====================================================
Return to [ 19 |
August |
1998 ]
The Southern California OS/2 User Group
P.O. Box 26904
Santa Ana, CA 92799-6904, USA
Copyright 2001 the Southern California OS/2 User Group. ALL RIGHTS
RESERVED.
SCOUG, Warp Expo West, and Warpfest are trademarks of the Southern California OS/2 User Group.
OS/2, Workplace Shell, and IBM are registered trademarks of International
Business Machines Corporation.
All other trademarks remain the property of their respective owners.
|