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.
The Jar tool puts a default manifest with pathname META-INF/MANIFEST. MF into any JAR file you create. You can add JAR file functionality, such as specifying an entry point, by modifying the default manifest. The m option allows you to add information to the default manifest while creating a JAR file.
The manifest is a special file that can contain information about the files packaged in a JAR file. By tailoring this "meta" information that the manifest contains, you enable the JAR file to serve a variety of purposes.
Run a Nonexecutable JAR with Arguments To run an application in a nonexecutable JAR file, we have to use -cp option instead of -jar. We'll use the -cp option (short for classpath) to specify the JAR file that contains the class file we want to execute: java -cp jar-file-name main-class-name [args …]
mf extension is a Java Manifest file that contains information about the individual JAR file entries. The MF file itself is contained inside the JAR file and provides all the extension and package-related definition. JAR files can be produced to be used as an executable file.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With