Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default arguments in JAR-manifest

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.

like image 520
pmf Avatar asked Nov 06 '09 19:11

pmf


People also ask

How do I specify JAR manifest?

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.

What is manifest in JAR?

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.

How do I run an argument from a JAR file?

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 …]

What is manifest MF in Java?

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.


1 Answers

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.

like image 108
Carl Smotricz Avatar answered Sep 21 '22 14:09

Carl Smotricz