问题
Is there a way to create a JAR-file that contains some arguments that are passed to the main class? (It does not matter whether it prepends or appends the arguments to potential command line arguments.)
I know I could simply write a bootstrapping class and specify this as main class (calling the real main class with the arguments), but this seems a bit awkward.
回答1:
To the best of my knowledge, no. You'll have to do that kind of thing yourself, in code.
A lot of people find it useful to write a little main class that sets up an environment and then acts as a ClassLoader for the "real" main program. Typically, such pre-mains fiddle with the classpath of their application, but your kind of problem is something else that could be solved like this.
回答2:
I would design the application to have default settings built in, and override the defaults if the user gives different arguments.
In your setup, what happens if the user gives arguments that are different? Wouldn't end up with multiple similar arguments and have to awkwardly handle that?
来源:https://stackoverflow.com/questions/1689692/default-arguments-in-jar-manifest