Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #13749 > unrolled thread
| Started by | "Hiram Hunt" <hiramhunt@verizon.net> |
|---|---|
| First post | 2012-04-21 15:11 -0400 |
| Last post | 2012-04-22 07:07 -0400 |
| Articles | 19 — 9 participants |
Back to article view | Back to comp.lang.java.programmer
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
| From | "Hiram Hunt" <hiramhunt@verizon.net> |
|---|---|
| Date | 2012-04-21 15:11 -0400 |
| Subject | Command-line options in a jar file |
| Message-ID | <4f93064c$0$5461$c3e8da3$eb767761@news.astraweb.com> |
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. 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 #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? -- Hiram Hunt
[toc] | [next] | [standalone]
| From | Lew <noone@lewscanon.com> |
|---|---|
| Date | 2012-04-21 13:17 -0700 |
| Message-ID | <jmv4la$b2f$1@news.albasani.net> |
| In reply to | #13749 |
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
[toc] | [prev] | [next] | [standalone]
| From | "Hiram Hunt" <hiramhunt@verizon.net> |
|---|---|
| Date | 2012-04-21 17:27 -0400 |
| Message-ID | <4f932622$0$9167$c3e8da3$9b4ff22a@news.astraweb.com> |
| In reply to | #13754 |
"Lew" <noone@lewscanon.com> wrote in message news:jmv4la$b2f$1@news.albasani.net... > 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. I have done that, but that is not what I am trying to do now. > >> 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. This was actual cut and paste of a Windows session. In this case, forward slashes would work with javac, but it is unnatural when using the Windows command prompt because they are not generally accepted there. For example, they will not work in the ftype file association shown below. > >> #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? I used -version to demonstrate the problem I was having getting a command-line option to be saved in a jar file for use when the jar file is executed. The specific option I used for the demonstration was just a convenient example, because the results can easily be seen. 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"). > > <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. I could (I think) add the command line options to the file association (I have already changed it from javaw.exe to java.exe), but then the options would apply to each jar file I execute. > > 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? > Very obvious, so yes I had already thought of it and used it, though mainly with .class files that were not in a jar file, but I am asking whether there is a way to pass the options in a jar file. Alternatively, I think I can set the property in the executable with System.setProperty(), but I am not sure what command could be used to set the memory option (-Xmxn) from within the program. -- Hiram Hunt
[toc] | [prev] | [next] | [standalone]
| From | Jan Burse <janburse@fastmail.fm> |
|---|---|
| Date | 2012-04-22 00:32 +0200 |
| Message-ID | <jmvcig$q1c$1@news.albasani.net> |
| In reply to | #13760 |
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
[toc] | [prev] | [next] | [standalone]
| From | "Hiram Hunt" <hiramhunt@verizon.net> |
|---|---|
| Date | 2012-04-21 19:23 -0400 |
| Message-ID | <4f93418b$0$32208$c3e8da3$670ba073@news.astraweb.com> |
| In reply to | #13765 |
"Jan Burse" <janburse@fastmail.fm> wrote in message news:jmvcig$q1c$1@news.albasani.net... > 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 > > Thanks. The stackoverflow link gets at the sort of thing I am trying to do. I don't see in the ProcessBuilder documentation a way to set memory size, though it does let one set system properties. I think I should just settle for running things in a less pretty way (batch file, e.g.) than I would like. Maybe someday a new option will be added for jar files to do this. -- Hiram Hunt
[toc] | [prev] | [next] | [standalone]
| From | Jan Burse <janburse@fastmail.fm> |
|---|---|
| Date | 2012-04-22 01:31 +0200 |
| Message-ID | <jmvg0g$v3l$2@news.albasani.net> |
| In reply to | #13773 |
Hiram Hunt schrieb: > trying to do. I don't see in the ProcessBuilder documentation http://silentdevelopment.blogspot.com/2010/03/how-to-set-or-increase-xmx-heap-memory.html
[toc] | [prev] | [next] | [standalone]
| From | "Hiram Hunt" <hiramhunt@verizon.net> |
|---|---|
| Date | 2012-04-21 20:10 -0400 |
| Message-ID | <4f934c5e$0$27555$c3e8da3$14a0410e@news.astraweb.com> |
| In reply to | #13775 |
"Jan Burse" <janburse@fastmail.fm> wrote in message news:jmvg0g$v3l$2@news.albasani.net... > Hiram Hunt schrieb: >> trying to do. I don't see in the ProcessBuilder documentation > > http://silentdevelopment.blogspot.com/2010/03/how-to-set-or-increase-xmx-heap-memory.html Okay. Thanks. I think what I was missing is that ProcessBuilder sets things up for a general process, not just something that you start with java.exe. Thus, if the general process you start is java.exe itself, you can pass any arguments you wish to it including the memory allocation argument. -- Hiram Hunt
[toc] | [prev] | [next] | [standalone]
| From | "John B. Matthews" <nospam@nospam.invalid> |
|---|---|
| Date | 2012-04-22 07:16 -0400 |
| Message-ID | <nospam-E0F95A.07163322042012@news.aioe.org> |
| In reply to | #13777 |
In article <4f934c5e$0$27555$c3e8da3$14a0410e@news.astraweb.com>, "Hiram Hunt" <hiramhunt@verizon.net> wrote: > I think what I was missing is that ProcessBuilder sets things up for > a general process, not just something that you start with java.exe. > Thus, if the general process you start is java.exe itself, you can > pass any arguments you wish to it including the memory allocation > argument. See also this gui.Launcher: <http://groups.google.com/group/comp.lang.java.programmer/msg/c81f8c5f269e22e5> -- John B. Matthews trashgod at gmail dot com <http://sites.google.com/site/drjohnbmatthews>
[toc] | [prev] | [next] | [standalone]
| From | "Hiram Hunt" <hiramhunt@verizon.net> |
|---|---|
| Date | 2012-04-22 13:15 -0400 |
| Message-ID | <4f943ca5$0$5622$c3e8da3$eb767761@news.astraweb.com> |
| In reply to | #13786 |
"John B. Matthews" <nospam@nospam.invalid> wrote in message news:nospam-E0F95A.07163322042012@news.aioe.org... > In article <4f934c5e$0$27555$c3e8da3$14a0410e@news.astraweb.com>, > "Hiram Hunt" <hiramhunt@verizon.net> wrote: > >> I think what I was missing is that ProcessBuilder sets things up for >> a general process, not just something that you start with java.exe. >> Thus, if the general process you start is java.exe itself, you can >> pass any arguments you wish to it including the memory allocation >> argument. > > See also this gui.Launcher: > > <http://groups.google.com/group/comp.lang.java.programmer/msg/c81f8c5f269e22e5> > Thanks. Having a GUI to launch the process is more than I need, but just looking over the code makes me a bit more comfortable with the concept of trying ProcessBuilder for my program. -- Hiram Hunt
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2012-04-21 22:05 -0400 |
| Message-ID | <4f936764$0$285$14726298@news.sunsite.dk> |
| In reply to | #13760 |
On 4/21/2012 5:27 PM, Hiram Hunt wrote:
> "Lew"<noone@lewscanon.com> wrote in message
> news:jmv4la$b2f$1@news.albasani.net...
>> On 04/21/2012 12:11 PM, Hiram Hunt wrote:
>>> #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?
>
> I used -version to demonstrate the problem I was having getting a
> command-line option to be saved in a jar file for use when the
> jar file is executed. The specific option I used for the demonstration
> was just a convenient example, because the results can easily be
> seen. 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").
Executable jar files does not support JVM args in manifest.
You options are:
1) specify the JVM args in the command line (does not work with
double click)
2) write a startup script (this is very common)
3) write your own startup executable that create the JVM with
the args you want (requires a build per supported platform)
Arne
[toc] | [prev] | [next] | [standalone]
| From | "Hiram Hunt" <hiramhunt@verizon.net> |
|---|---|
| Date | 2012-04-22 07:10 -0400 |
| Message-ID | <4f93e739$0$2303$c3e8da3$c8b7d2e6@news.astraweb.com> |
| In reply to | #13779 |
"Arne Vajhøj" <arne@vajhoej.dk> wrote in message news:4f936764$0$285$14726298@news.sunsite.dk... > On 4/21/2012 5:27 PM, Hiram Hunt wrote: >> .... > .... Thanks. -- Hiram Hunt
[toc] | [prev] | [next] | [standalone]
| From | Martin Gregorie <martin@address-in-sig.invalid> |
|---|---|
| Date | 2012-04-21 21:21 +0000 |
| Message-ID | <jmv8c3$fka$1@localhost.localdomain> |
| In reply to | #13749 |
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 |
[toc] | [prev] | [next] | [standalone]
| From | "Hiram Hunt" <hiramhunt@verizon.net> |
|---|---|
| Date | 2012-04-21 17:43 -0400 |
| Message-ID | <4f932a25$0$4810$c3e8da3$10694f1e@news.astraweb.com> |
| In reply to | #13759 |
"Martin Gregorie" <martin@address-in-sig.invalid> wrote in message news:jmv8c3$fka$1@localhost.localdomain... > 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. > .... Thanks. Yes, I know I can put options before the -jar option, but I would like to be able to just run the program as "MyProgram.jar" by using the ftype association in my original post. Thus, my question is about passing arguments for java.exe in the jar file. My guess at this point is that it is not possible. -- Hiram Hunt
[toc] | [prev] | [next] | [standalone]
| From | Patricia Shanahan <pats@acm.org> |
|---|---|
| Date | 2012-04-21 15:01 -0700 |
| Message-ID | <mPCdnbT9KJTMsw7SnZ2dnUVZ_hadnZ2d@earthlink.com> |
| In reply to | #13761 |
On 4/21/2012 2:43 PM, Hiram Hunt wrote:
...
> Thanks. Yes, I know I can put options before the -jar option, but I would
> like to be able to just run the program as "MyProgram.jar" by using the
> ftype association in my original post. Thus, my question is about passing
> arguments for java.exe in the jar file. My guess at this point is that it
> is
> not possible.
Remember that a Java main is just a static method, and can be called.
You could write, include in your jar, and make the main class something
like this:
=====WARNING===UNTESTED=CODE========
public class Wrapper {
private static String[] actualArgs = {
"arg1",
"arg2",
}
public static void main(String[] args) {
HelloWorld.main(actualArgs);
}
}
====================================
[toc] | [prev] | [next] | [standalone]
| From | "Hiram Hunt" <hiramhunt@verizon.net> |
|---|---|
| Date | 2012-04-21 18:56 -0400 |
| Message-ID | <4f933afc$0$1649$c3e8da3$92d0a893@news.astraweb.com> |
| In reply to | #13764 |
"Patricia Shanahan" <pats@acm.org> wrote in message
news:mPCdnbT9KJTMsw7SnZ2dnUVZ_hadnZ2d@earthlink.com...
> On 4/21/2012 2:43 PM, Hiram Hunt wrote:
> ...
>> Thanks. Yes, I know I can put options before the -jar option, but I
>> would
>> like to be able to just run the program as "MyProgram.jar" by using the
>> ftype association in my original post. Thus, my question is about
>> passing
>> arguments for java.exe in the jar file. My guess at this point is that
>> it
>> is
>> not possible.
>
> Remember that a Java main is just a static method, and can be called. You
> could write, include in your jar, and make the main class something like
> this:
>
> =====WARNING===UNTESTED=CODE========
> public class Wrapper {
> private static String[] actualArgs = {
> "arg1",
> "arg2",
> }
> public static void main(String[] args) {
> HelloWorld.main(actualArgs);
> }
> }
> ====================================
>
Thanks, but those are not the arguments I am trying to
work with. I am trying to pass arguments to the java
virtual machine, not to main(). I want to use -Xmxn and
-Dthis=that (with appropriate substitutions for "n" and
"this=that"). Java.exe needs to see them. Alternatively,
I think I could use "System.setProperty()" first in main(),
but I don't know what I could call in main() to produce
the same effect as -Xmxn. The -Dthis=that is to prevent
a conflict that might only occur _rarely_ in a library I
am using, so I would have a hard time checking directly
whether setting it in main() is really soon enough.
The actual option is -Dsun.java2d.noddraw=true .
I am hoping to be able to run the program in a "pretty"
way -- just type MyProgram.jar without having to give
certain fixed, mandatory arguments every time and without
resorting to a batch file. In the end, I don't think
it will be possible. It is not a show stopper, just an
annoyance.
-- Hiram Hunt
[toc] | [prev] | [next] | [standalone]
| From | Knute Johnson <nospam@knutejohnson.com> |
|---|---|
| Date | 2012-04-21 15:34 -0700 |
| Message-ID | <jmvckp$866$1@dont-email.me> |
| In reply to | #13749 |
On 4/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. > > 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 > > #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? > > -- Hiram Hunt I don't think the -J option does what you think it does. It does not appear to cause the launcher, java.exe, to use the option you specified with the -J when you compiled it or jar'd it. I think it passes that to the runtime that does the compiling and jar'ing. To be specific in your example above, I think the -showversion option was passed to the java runtime that was used to by the jar.exe program to create your jar file. And that is why it shows up when you run it as above. If you want a command line option when you run your program, you will have to pass the arguments on the command line or by Patricia's method in a call to the main() method. -- Knute Johnson
[toc] | [prev] | [next] | [standalone]
| From | "Hiram Hunt" <hiramhunt@verizon.net> |
|---|---|
| Date | 2012-04-21 19:04 -0400 |
| Message-ID | <4f933cea$0$24650$c3e8da3$e408f015@news.astraweb.com> |
| In reply to | #13766 |
"Knute Johnson" <nospam@knutejohnson.com> wrote in message news:jmvckp$866$1@dont-email.me... > On 4/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. >> >> 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 >> >> #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? >> >> -- Hiram Hunt > > I don't think the -J option does what you think it does. It does not > appear to cause the launcher, java.exe, to use the option you specified > with the -J when you compiled it or jar'd it. I think it passes that to > the runtime that does the compiling and jar'ing. To be specific in your > example above, I think the -showversion option was passed to the java > runtime that was used to by the jar.exe program to create your jar file. > And that is why it shows up when you run it as above. > > If you want a command line option when you run your program, you will have > to pass the arguments on the command line or by Patricia's method in a > call to the main() method. > Thanks. Actually, I already had figured out what -J was doing. I showed in my original post what it was doing in hopes that people who had not tried it would not reply that -J was the answer to my problem. -- Hiram Hunt
[toc] | [prev] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2012-04-21 23:18 -0700 |
| Message-ID | <jk87p79gh89gbdeektn15po8vk5v0n85o0@4ax.com> |
| In reply to | #13749 |
On Sat, 21 Apr 2012 15:11:14 -0400, "Hiram Hunt" <hiramhunt@verizon.net> wrote, quoted or indirectly quoted someone who said : >Hello, > >Is there a way to pass command-line options to java.exe >with an executable jar file? There is no way to put command line arguments destined for java.exe inside the jar in the manifest. However, if you use JWS, you can put them in the JNLP file which lives outside the jar. The reason for this is, by the time the java.exe JVM (Java Virtual Machine) gets around to looking inside jars, it has already cast in stone everything it learned from the command line. ~ http://mindprod.com/jgloss/jar.html#MANIFEST -- Roedy Green Canadian Mind Products http://mindprod.com When you were a child, if you did your own experiment to see if it was better to put to cocoa into your cup first or the hot milk first, then you likely have the programmer gene..
[toc] | [prev] | [next] | [standalone]
| From | "Hiram Hunt" <hiramhunt@verizon.net> |
|---|---|
| Date | 2012-04-22 07:07 -0400 |
| Message-ID | <4f93e679$0$2190$c3e8da3$9f400e27@news.astraweb.com> |
| In reply to | #13781 |
"Roedy Green" <see_website@mindprod.com.invalid> wrote in message news:jk87p79gh89gbdeektn15po8vk5v0n85o0@4ax.com... > On Sat, 21 Apr 2012 15:11:14 -0400, "Hiram Hunt" > <hiramhunt@verizon.net> wrote, quoted or indirectly quoted someone who > said : > >>.... >.... Thanks. -- Hiram Hunt
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web