Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1091311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:30:26+00:00 2026-05-16T23:30:26+00:00

I have a Java main application with somewhat complex command line arguments. These arguments

  • 0

I have a Java main application with somewhat complex command line arguments. These arguments are currently processed by a CommandLineArgumentProcessor class. Here’s what my code current looks like:

public static void main(String[] args) {
   Injector injector = Guice.createInjector(new ConfigModule(), new WorkModule(), new ReportModule);
   injector.getInstance(I_CommandLineArgumentProcessor.class).processArguments(args);
   //Its not until here that I know if I should stub or not with this implementation
   ...
}

I am now implementing a way to stub out some classes for system testing. To do this I need to swap some of the bindings which Guice uses. Then on the command line I will specify certain flags to turn on/off stubbing of various functionality. However, my problem is that the arguments aren’t processed until after the injector is created.

Do I need to have separate logic to process my stubbing flags prior to creating the injector and then conditionally create the appropriate injector? I’m hesitant on this approach because it divides the logic of processing the command line arguments into two areas of code. Or, is there another (appropriate) way to get Guice to substitute various objects/sub-trees in the object graph after the injector is created? Or do I have one injector for the command line processor and then create another one for the remainder of the modules?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T23:30:27+00:00Added an answer on May 16, 2026 at 11:30 pm

    An injector’s bindings are immutable once it’s created (though the bindings themselves can be dynamic). I’d suggest first creating an injector that only binds what you need to do the command line processing. Then do the command line processing, get the flags, and use them when creating another injector that the actual application will use. If there’s stuff you need to bind to be able to do the command line processing that the rest of the application will need as well, you could just create the second injector as a child injector of the first.

    There are probably some other weird things you can do, such as having a mutable singleton that the command line flags are set on and using provider methods that depend on that object:

    @Provides
    protected Foo provideFoo(Config config) {
      return config.isStubFoo() ? new StubFoo() : new RealFoo();
    }
    

    But I think the first approach is much preferable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a java application where main class is dependent with some other classes.
I have a java main application, and I want to use log4j. I don't
I have a small Java test app in Netbeans where the main() class reads
Java newbie. I am trying to run a java main class from cmd line
I have a main application that is coded with Java, but I want to
I have a main application frame ( MainFrame class ). On actionperformed event of
I have four activities namely, Demo_tabActivity.java [main activity] Tabhost.java The below two activities are
I have four activities namely, Demo_tabActivity.java [main activity] Tabhost.java The below two activities are
Example: For(int i=0; i<4; i++) playSound(Sound.wav); I have the following classes: Main import java.io.IOException;
I have read somewhere one of the main differences between Java and C++/C# is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.