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


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

Re: Command-line options in a jar file

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.albasani.net!.POSTED!not-for-mail
From Lew <noone@lewscanon.com>
Newsgroups comp.lang.java.programmer
Subject Re: Command-line options in a jar file
Date Sat, 21 Apr 2012 13:17:45 -0700
Organization albasani.net
Lines 65
Message-ID <jmv4la$b2f$1@news.albasani.net> (permalink)
References <4f93064c$0$5461$c3e8da3$eb767761@news.astraweb.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace news.albasani.net TUNGoSq9SwsOzBnuGFgTCNpXIkXaQohCBsZ3QsplDbTgbz+mGUN03wrN1x/Juic+6QvXtP7y55W6ZF/18bDT3RZGrn82lPe6a/1HH+X1ZW65fJDLy3JB3jiZxdwvmQYF
NNTP-Posting-Date Sat, 21 Apr 2012 20:17:46 +0000 (UTC)
Injection-Info news.albasani.net; logging-data="cE6ACnJsfMdGBFvqj12MfaxCIPTQfa8inWUZMFZvssOA5V2LS+ctpZ4kY1un268Xa0OvP19yp5tsjcyFcOD4yN28pxS7cqPSjlz06TcpIkhnbc63X5aTNr2K6B7f4IGf"; mail-complaints-to="abuse@albasani.net"
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120329 Thunderbird/11.0.1
In-Reply-To <4f93064c$0$5461$c3e8da3$eb767761@news.astraweb.com>
Cancel-Lock sha1:QOzAO5Gq1GWpmhVy6a2Gi9t+7E0=
Xref csiph.com comp.lang.java.programmer:13754

Show key headers only | View raw


On 04/21/2012 12:11 PM, Hiram Hunt wrote:
> Hello,
>
> 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.

Pass them on the command line with the "java" command.

> Trying things out with a simple HelloWorld program, when I
> use -J-showversion or -J-verbose, the extra output comes
> when the jar file is being created, not when it is being
> run.  I was using Windows SP3 and Java 7u3.  I also tried
> under Windows 7 a program that prints system properties
> (retrieved with System.getProperties()) under Windows 7
> and a -J-Dthis=that option, but the property did not appear
> in the output.
>
> Specifically, with Windows SP3 and the command prompt:
>
> #javac hi\HelloWorld.java

Please don't use backslashes as path separators, at least not here. It's very 
disconcerting as they have special meaning for Java and non-Windows shells. 
Windows handles forward slashes as path separators, so there's no reason not 
to use them in Usenet posts.

> #jar cfe hi.jar hi.HelloWorld hi\HelloWorld.class -J-showversion
> java version "1.7.0_03"
> Java(TM) SE Runtime Environment (build 1.7.0_03-b05)
> Java HotSpot(TM) Client VM (build 22.1-b02, mixed mode, sharing)
>
>
> #ftype jarfile
> jarfile="C:\Program Files\Java\jre7\bin\java.exe" -jar "%1%" %*
>
> #hi.jar
> Hello, world
>
> #
>
> Is there a way to (in this example) get the version information
> to show up when running hi.jar instead of when running jar itself?

Version of what? Java itself, as you show here? What's wrong with using the 
"java" command for that?

<http://docs.oracle.com/javase/7/docs/>

Does Windows 7 let you specify command options with the file association? I 
never invoke JARs without an explicit invocation of the "java" command; I 
suggest you follow that practice.

You can put the invocation in a shell script and pass all the options your 
little heart desires to the "java" command. That seems like the obvious 
approach, yes?

-- 
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg

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