Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #13765

Re: Command-line options in a jar file

From Jan Burse <janburse@fastmail.fm>
Newsgroups comp.lang.java.programmer
Subject Re: Command-line options in a jar file
Date 2012-04-22 00:32 +0200
Organization albasani.net
Message-ID <jmvcig$q1c$1@news.albasani.net> (permalink)
References <4f93064c$0$5461$c3e8da3$eb767761@news.astraweb.com> <jmv4la$b2f$1@news.albasani.net> <4f932622$0$9167$c3e8da3$9b4ff22a@news.astraweb.com>

Show all headers | View raw


Hiram Hunt schrieb:
> As I said before, the options I actually care about (today, anyway)
> are -Xmxn and -Dthis=that (with appropriate values to be substituted
> for "n" and "this=that").

Hi,

The syntax the java command line in case of a .jar is:

    java [ options ] -jar file.jar [ argument ... ]

The -X and the -D option can be placed before the -jar.
But I also did not find a method to place it into a
manifest. Definition for:

    -Dproperty=value

Is that it will set a system property value. So right,
this can be done inside your .jar. And arguments are
passed to main() this can be also done inside your .jar.
But for the -X options I don't see a way, since:

    Options that begin with -X are non-standard
    (not guaranteed to be supported on all VM
    implementations), and are subject to change
    without notice in subsequent releases of
    the JDK.

To modify a -X option inside your .jar seems hope
less. Not because they are non standard. But because
most of them are immutable and take effect when the
JVM is initialized. So when your main() is invoked
it is already too late.

I was once hoping that I can for example change the
heap size via a management bean. But I didn't find
an appropriate method here:

         Package java.lang.management
	http://docs.oracle.com/javase/7/docs/api/java/lang/management/package-summary.html

So I guess what some tools do is that they fork
a Process and pass the parameters they want. This
can be done inside a jar.

         Class ProcessBuilder
 
http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/ProcessBuilder.html

But this seems also risky and ugly, same as writing
small scripts. The following stack overflow answer
additionally lists launch4j and JavaWeb Start as
an alternative:

http://stackoverflow.com/questions/1018217/can-i-set-java-max-heap-size-for-running-from-a-jar-file

Didn't try either...

Bye

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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