Re: Obtaining launch arguments in XCode/java (NSProperties?)

From: Brendan Duddridge (brenda..lickspace.com)
Date: Fri Jan 28 2005 - 07:59:02 EST

  • Next message: John C. Beatty: "Re: Obtaining launch arguments in XCode/java (NSProperties?)"

    We usually use something like this:

    String myValue = NSProperties.getProperty("MyParam");

    Or with a built-in default value:

    String myValue = NSProperties.getProperty("MyParam", "MyDefaultValue");

    I read somewhere that it's better to use NSProperties, especially if you
    want to deploy into a servlet environment.

    ___________________________

    Brendan Duddridge

    ClickSpace Interactive Inc.
    Suite L100
    239 - 10th Ave SE
    Calgary, AB T2G 0V9
    Canada
    (403) 277-5591
    http://www.clickspace.com/

    > From: Chuck Hill <chil..lobal-village.net>
    > Date: Thu, 27 Jan 2005 11:24:26 -0800
    > To: "John C. Beatty" <jcbeatt..waterloo.ca>
    > Cc: <woproject-de..bjectstyle.org>
    > Subject: Re: Obtaining launch arguments in XCode/java (NSProperties?)
    >
    > The bad news: you're wasting your time.
    > The good news: you don't need to do anything.
    >
    > On the command line:
    > ... -DMyParam=MyValue
    >
    > In the app
    > String myParam = System.getProperty("MyParam");
    >
    > now myParam.equals("MyValue")
    >
    > Chuck
    >
    >
    >
    > On Jan 27, 2005, at 9:10 AM, John C. Beatty wrote:
    >
    >> Executive summary - what's the officially sanctioned way of getting
    >> launch arguments, whether supplied on the command line (java ...) or
    >> when executing a java app within XCode?
    >>
    >> Details: I have a java tool that populates a MySQL databases presented
    >> to clients via WebObjects. Various parameters are supplied to the tool
    >> as launch arguments (= command line arguments). It ran fine when first
    >> written a year or two ago, but with the current version of WO (5.2.3)
    >> crashes with the error message
    >>
    >> Exception in thread "main" java.lang.ExceptionInInitializerError
    >> at java.lang.Class.forName0(Native Method)
    >> at java.lang.Class.forName(Class.java:141)
    >> at
    >> com.webobjects.foundation.NSProperties.setPropertiesFromArgv(NSProperti
    >> es.java:395)
    >> at fmpToMySQL.main(fmpToMySQL.java:77)
    >> Caused by: java.lang.NullPointerException
    >> at
    >> com.webobjects.foundation.NSBundle.LoadUserAndBundleProperties(NSBundle
    >> .java:640)
    >> at com.webobjects.foundation.NSBundle.<clinit>(NSBundle.java:367)
    >> ... 4 more
    >>
    >> A minimal test program that duplicates this behaviour looks like this:
    >>
    >> import java.util.*;
    >> import com.webobjects.foundation.*;
    >>
    >> public class TestLaunchArguments {
    >>
    >> private static Properties props;
    >>
    >> public static void main ( String args[] ) {
    >> NSProperties.setPropertiesFromArgv( args );
    >> props = System.getProperties();
    >> String argString = props.getProperty("test");
    >> if( argString == null ) {
    >> System.out.println( "Couldn't find -test <argument>" );
    >> } else
    >> System.out.println( "-test " + argString );
    >> }
    >> }
    >>
    >> I can still get my java tool to run by packaging it with the WO jar
    >> files I used at the time I wrote it, but as I say it crashes when run
    >> with the current release of WebObjects.
    >>
    >> Although most of NSProperty's methods are now deprecated, it's clear
    >> that I need the NSProperties.setPropertiesFromArgv() call to get
    >> launch arguments merged with the system properties (or a call to
    >> something something...) - the arguments don't show up in args, whether
    >> run from XCode or directly from a shell via java... .
    >>
    >> In the Java tool (ie not in the test app above), if I hardwire in the
    >> various parameters and comment out the
    >> NSProperties.setPropertiesFromArgv() call, I get the same error
    >> message a bit later in the program while executing an EO method.
    >> Perhaps some piece of EO is looking for a property file that doesn't
    >> exist, or is finding one I'm unaware of that contains bad content?
    >>
    >> I've poked around extensively in Apple's documentation, in various
    >> mailing lists, and with google, but not found anything useful.
    >>
    >> If this IS the right way for java code to get its hands on launch
    >> arguments in OS X, can someone tell me what I'm doing wrong or what
    >> com.webobjects.foundation is looking for?
    >>
    >> If it's NOT the right way for java code to get its hands on launch
    >> arguments in OS X, I'd be infinitely grateful if someone could tell me
    >> what I *should* be doing. A pointer to documentation I've missed would
    >> be great, but preferably documentation that doesn't leave out
    >> essential details :-)...
    >>
    >> Thanks in advance,
    >> john beaty
    >> --
    >> ------------------------------
    >> Prof. John C. Beatty
    >> School of Computer Science
    >> University of Waterloo
    >> 200 University Avenue
    >> Waterloo, Ontario
    >> Canada N2L 3G1
    >> +1 (519) 888-4567 x 4525 voice
    >> +1 (519) 885-1208 fax
    >>
    > --
    > Practical WebObjects - a book for intermediate WebObjects developers
    > who want to increase their overall knowledge of WebObjects, or those
    > who are trying to solve specific application development problems.
    > http://www.global-village.net/products/practical_webobjects
    >
    >
    >



    This archive was generated by hypermail 2.0.0 : Fri Jan 28 2005 - 07:59:10 EST