Results 1 to 10 of 13

Thread: command line parameters in RCP-application?

Hybrid View

  1. #1
    Join Date
    Apr 2005
    Location
    Finland
    Posts
    314

    Default command line parameters in RCP-application?

    I'm launching the my Spring RCP-application by following method and it works otherwise properly but ... I'm not able to use any of the command line arguments (args array). So the question goes: How do I set the command line parameters in my application?

    public class Main {
    public static void main(String[] args) {
    String startupContext = ...;
    String richclientApplicationContext = ...;
    String applicationContext = ...;
    new ApplicationLauncher(startupContext, new String[] {richclientApplicationContext, applicationContext});
    }

    I don't wan't to use the beans/properties in

  2. #2

    Default Using a different BeanPostProcessors depending on the args[]?

    I am not sure what you are trying to do with your paramaters, however one of the most usefull things is you can configure spring depending on the args passed in. Like this:

    Code:
    public class Main {
    public static void main(String[] args) {
    
    //do arg check...
    String mode = args[0];
    ConfigurableBeanFactory bf = new .....;     // create BeanFactory
       ...                       // now register some beans
    // now register any needed BeanPostProcessors
    MyBeanPostProcessor pp = new MyBeanPostProcessor();
    bf.addBeanPostProcessor(pp);
    
    // now start using the factory
    
    }
    http://www.springframework.org/docs/...ry-customizing

  3. #3
    Join Date
    Apr 2005
    Location
    Finland
    Posts
    314

    Default more detailed info

    Thanks for the reply. Here are some detailed information regarding the problem I'm having here.

    In my Spring RCP-application, I launch it by using the code above. The application is launched with some command line parameters which varies depending on the user who launched the application. There are couple of these parameters.

    For somereason I don't find any way to launch my RCP application including both the beans in applicationContext.xml files and these command line arguments.

    I've tried already the 'PropertyPlaceholderConfigurer' to set the new properties into the beans but this doesn't affect on the applicationContext once it's been loaded.

    The main aim in here is to get the command line arguments so that they are available to my business class in my RCP-application. Also "non Spring" solutions and hints are welcome !!

    Thanks

  4. #4

    Default construct the applicationContext, then richclient...

    Have you tried:
    Code:
             String[] contextFiles = new String[]
             { root + "richclient-application-context.xml", root + "richclient-preference-context.xml" };
    
             Launcher.setMessage("Initializing datawarehouse...");
             ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(contextFiles);
             
    // create placeholderconfigurer to bring in some property
    // values from a Properties file
    PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
    cfg.setLocation(new FileSystemResource("jdbc.properties"));
    // now actually do the replacement
    cfg.postProcessBeanFactory(factory);
    
             Launcher.setMessage("Initializing gui components and services...");
             ApplicationLauncher launcher = new ApplicationLauncher(context);
    This will do the trick, before rich-client was constructing the beans before you binded the postProcessBeanFactory
    Last edited by mlavwilson2; Mar 2nd, 2006 at 07:42 AM.

  5. #5
    Join Date
    Jul 2007
    Posts
    17

    Default

    I think it is interesting that the splash screen with progress monitor can be used with ApplicationLauncher(String startupContextPath, ApplicationContext rootApplicationContext).

    The actual implementation needs a loaded ApplicationContext, causing the splash to be showed late.

    I think an AbstractApplicationContext can be passed instead of the ApplicationContext and refreshed if necessary inside the constructor, so the progress can be showed.

  6. #6
    Join Date
    Feb 2006
    Posts
    118

    Default

    Is this the recommended way of passing/processing arguments to the application? Using a BeanPostProcessor?

    It sounds somewhat clunky, since it means that the splashscreen won't get shown until the whole application context has been initialized and processed.

    Would it make sense to have another ApplicationLauncher constructor that accepts a BeanPostProcessor as an argument, that gets applied to all contexts as they are constructed and read, similarly to the ProgressMonitoringBeanFactoryPostProcessor?

    Or is there a better way of doing this?

    To be honest, even with the PostProcessor, I'm still looking for an example of how to actually implement this.

    For example, picture a text editor. If you provide a filename on the command line, it opens it and lets you edit it. Otherwise, it prompts for a file to edit. In the context of Spring Rich client, the "prompt command" is triggered from the LifecycleAdvisor's onPostStartup() handler.

    One *VERY* dirty way of doing it would be to just save the main args[] as a static variable in my startup class, and then reference them directly when required, but that just makes my skin crawl to suggest it! :-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •