Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #13759
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!usenet.ukfsn.org!not-for-mail |
|---|---|
| From | Martin Gregorie <martin@address-in-sig.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Command-line options in a jar file |
| Date | Sat, 21 Apr 2012 21:21:07 +0000 (UTC) |
| Organization | UK Free Software Network |
| Lines | 32 |
| Message-ID | <jmv8c3$fka$1@localhost.localdomain> (permalink) |
| References | <4f93064c$0$5461$c3e8da3$eb767761@news.astraweb.com> |
| NNTP-Posting-Host | 84.45.235.129 |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 8bit |
| X-Trace | localhost.localdomain 1335043267 16010 84.45.235.129 (21 Apr 2012 21:21:07 GMT) |
| X-Complaints-To | usenet@localhost.localdomain |
| NNTP-Posting-Date | Sat, 21 Apr 2012 21:21:07 +0000 (UTC) |
| User-Agent | Pan/0.135 (Tomorrow I'll Wake Up and Scald Myself with Tea; GIT 30dc37b master) |
| Xref | csiph.com comp.lang.java.programmer:13759 |
Show key headers only | View raw
On Sat, 21 Apr 2012 15:11:14 -0400, Hiram Hunt wrote:
> Is there a way to pass command-line options to java.exe with an
> executable jar file? The "Jar tool reference page for Windows" seems to
> say that the -J option should do it, but when I try it out, the option
> is sent to the java virtual machine when I run the jar command, not when
> I run the executable jar file. I want to send -Xmxn and -Dthis=that
> options to java.exe.
>
Use the "Main-Class: full.class.name" directive in the jarfile's manifest
to select the program to be executed and then run it with the command:
java -jar jarfile_absolute_name arguments...
which passes the argument list to "static void main(String[] args) in
full.class.name via args. If you need to pass options to the JVM, they
are put in front of the -jar option.
If I want to be able to choose one candidate program out of several in
the jar file, I use the Main-Class to run a simple launcher program and
pass it the program name as its first argument. The launcher program uses
Class.forName() to load the required program and then starts it by
calling a method, which must not have the "static void main(String[])"
signature. I typically use via a method with the "void run(String[] args)"
signature and pass it all the command line arguments except the first via
args.
--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Command-line options in a jar file "Hiram Hunt" <hiramhunt@verizon.net> - 2012-04-21 15:11 -0400
Re: Command-line options in a jar file Lew <noone@lewscanon.com> - 2012-04-21 13:17 -0700
Re: Command-line options in a jar file "Hiram Hunt" <hiramhunt@verizon.net> - 2012-04-21 17:27 -0400
Re: Command-line options in a jar file Jan Burse <janburse@fastmail.fm> - 2012-04-22 00:32 +0200
Re: Command-line options in a jar file "Hiram Hunt" <hiramhunt@verizon.net> - 2012-04-21 19:23 -0400
Re: Command-line options in a jar file Jan Burse <janburse@fastmail.fm> - 2012-04-22 01:31 +0200
Re: Command-line options in a jar file "Hiram Hunt" <hiramhunt@verizon.net> - 2012-04-21 20:10 -0400
Re: Command-line options in a jar file "John B. Matthews" <nospam@nospam.invalid> - 2012-04-22 07:16 -0400
Re: Command-line options in a jar file "Hiram Hunt" <hiramhunt@verizon.net> - 2012-04-22 13:15 -0400
Re: Command-line options in a jar file Arne Vajhøj <arne@vajhoej.dk> - 2012-04-21 22:05 -0400
Re: Command-line options in a jar file "Hiram Hunt" <hiramhunt@verizon.net> - 2012-04-22 07:10 -0400
Re: Command-line options in a jar file Martin Gregorie <martin@address-in-sig.invalid> - 2012-04-21 21:21 +0000
Re: Command-line options in a jar file "Hiram Hunt" <hiramhunt@verizon.net> - 2012-04-21 17:43 -0400
Re: Command-line options in a jar file Patricia Shanahan <pats@acm.org> - 2012-04-21 15:01 -0700
Re: Command-line options in a jar file "Hiram Hunt" <hiramhunt@verizon.net> - 2012-04-21 18:56 -0400
Re: Command-line options in a jar file Knute Johnson <nospam@knutejohnson.com> - 2012-04-21 15:34 -0700
Re: Command-line options in a jar file "Hiram Hunt" <hiramhunt@verizon.net> - 2012-04-21 19:04 -0400
Re: Command-line options in a jar file Roedy Green <see_website@mindprod.com.invalid> - 2012-04-21 23:18 -0700
Re: Command-line options in a jar file "Hiram Hunt" <hiramhunt@verizon.net> - 2012-04-22 07:07 -0400
csiph-web