Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #13586 > unrolled thread
| Started by | Tim Slattery <Slattery_T@bls.gov> |
|---|---|
| First post | 2012-04-16 14:46 -0400 |
| Last post | 2012-04-17 04:24 -0700 |
| Articles | 17 — 8 participants |
Back to article view | Back to comp.lang.java.programmer
Self-executing JAR Tim Slattery <Slattery_T@bls.gov> - 2012-04-16 14:46 -0400
Re: Self-executing JAR Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-04-16 12:21 -0700
Re: Self-executing JAR markspace <-@.> - 2012-04-16 12:22 -0700
Re: Self-executing JAR Tim Slattery <Slattery_T@bls.gov> - 2012-04-16 16:34 -0400
Re: Self-executing JAR Lew <lewbloch@gmail.com> - 2012-04-16 14:26 -0700
Re: Self-executing JAR "John B. Matthews" <nospam@nospam.invalid> - 2012-04-16 21:06 -0400
Re: Self-executing JAR Knute Johnson <nospam@knutejohnson.com> - 2012-04-16 14:35 -0700
Re: Self-executing JAR markspace <-@.> - 2012-04-16 14:51 -0700
Re: Self-executing JAR markspace <-@.> - 2012-04-16 15:00 -0700
Re: Self-executing JAR Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2012-04-17 08:31 +0000
Re: Self-executing JAR markspace <-@.> - 2012-04-17 07:35 -0700
Re: Self-executing JAR Lew <lewbloch@gmail.com> - 2012-04-16 15:51 -0700
Re: Self-executing JAR Tim Slattery <Slattery_T@bls.gov> - 2012-04-17 08:56 -0400
Re: Self-executing JAR Tim Slattery <Slattery_T@bls.gov> - 2012-04-17 10:49 -0400
Re: Self-executing JAR markspace <-@.> - 2012-04-17 07:57 -0700
Re: Self-executing JAR Tim Slattery <Slattery_T@bls.gov> - 2012-04-18 09:06 -0400
Re: Self-executing JAR Roedy Green <see_website@mindprod.com.invalid> - 2012-04-17 04:24 -0700
| From | Tim Slattery <Slattery_T@bls.gov> |
|---|---|
| Date | 2012-04-16 14:46 -0400 |
| Subject | Self-executing JAR |
| Message-ID | <tvpoo7h83ooo9dk54gghqg8v805mlrkpf3@4ax.com> |
I must be doing something stupid.
I have a very simple command-line program in Eclipse, just a
System.out.println("Hello World"). It runs just fine in the IDE. So I
use File|Export|Export, and select "Runnable JAR file". A JAR is
created.
And it doesn't work. I can double-click on it, or I can call it from a
command line. I get nothing. No "Hello world", no error message, no
nothing. What have I missed?
--
Tim Slattery
Slattery_T@bls.gov
[toc] | [next] | [standalone]
| From | Daniel Pitts <newsgroup.nospam@virtualinfinity.net> |
|---|---|
| Date | 2012-04-16 12:21 -0700 |
| Message-ID | <Ci_ir.1762$Ec.850@newsfe16.iad> |
| In reply to | #13586 |
On 4/16/12 11:46 AM, Tim Slattery wrote:
> I must be doing something stupid.
>
> I have a very simple command-line program in Eclipse, just a
> System.out.println("Hello World"). It runs just fine in the IDE. So I
> use File|Export|Export, and select "Runnable JAR file". A JAR is
> created.
>
> And it doesn't work. I can double-click on it, or I can call it from a
> command line. I get nothing. No "Hello world", no error message, no
> nothing. What have I missed?
You have missed the SSCCE.
It could be that you need to set a "main" class in your build
configuration somewhere. I don't know much about Eclipse.
I do know that there is a standard file in META-INF that points to the
class that should be run to start the runnable jar. Google may tell you
more.
[toc] | [prev] | [next] | [standalone]
| From | markspace <-@.> |
|---|---|
| Date | 2012-04-16 12:22 -0700 |
| Message-ID | <jmhrgt$2qf$1@dont-email.me> |
| In reply to | #13586 |
On 4/16/2012 11:46 AM, Tim Slattery wrote:
> I must be doing something stupid.
>
> I have a very simple command-line program in Eclipse, just a
> System.out.println("Hello World"). It runs just fine in the IDE. So I
> use File|Export|Export, and select "Runnable JAR file". A JAR is
> created.
>
> And it doesn't work. I can double-click on it, or I can call it from a
> command line. I get nothing. No "Hello world", no error message, no
> nothing. What have I missed?
>
How do you "call it from the command line?" Show us the command line
and its output. You'll need a properly set PATH variable to the Java
runtime for this to work of course. Have you done that?
What OS do you have? You man have to set a file association from
Windows so you can double click on a Jar file.
Etc. Needs more info....
[toc] | [prev] | [next] | [standalone]
| From | Tim Slattery <Slattery_T@bls.gov> |
|---|---|
| Date | 2012-04-16 16:34 -0400 |
| Message-ID | <i90po791d7luqcjsm4k2h5eoa72i23g8af@4ax.com> |
| In reply to | #13586 |
Tim Slattery <Slattery_T@bls.gov> wrote:
>I must be doing something stupid.
>
>I have a very simple command-line program in Eclipse, just a
>System.out.println("Hello World"). It runs just fine in the IDE. So I
>use File|Export|Export, and select "Runnable JAR file". A JAR is
>created.
>
>And it doesn't work. I can double-click on it, or I can call it from a
>command line. I get nothing. No "Hello world", no error message, no
>nothing. What have I missed?
More info:
Here's the class:
public class Main {
public static void main(String[] args)
{
System.out.println("Here I am!");
try
{
SimpleDateFormat sdf = new
SimpleDateFormat("MM/dd/yyyy");
sdf.setLenient(false);
Date mydate = sdf.parse("2/29/1900");
System.out.println("Good date: " + mydate.toString());
}
catch (ParseException ex)
{
System.out.println("ParseException: " +
ex.getMessage());
}
}
/* (non-Java-doc)
* @see java.lang.Object#Object()
*/
public Main() {
super();
}
I export "Main.jar". To invoke from the command line, I type
"Main.jar". Nothing but a command prompt. I have jedit installed. If I
go to its directory and type "jedit.jar", it jumps right up. Therefore
I assume that the JRE can be found.
--
Tim Slattery
Slattery_T@bls.gov
[toc] | [prev] | [next] | [standalone]
| From | Lew <lewbloch@gmail.com> |
|---|---|
| Date | 2012-04-16 14:26 -0700 |
| Message-ID | <27365251.1727.1334611607107.JavaMail.geo-discussion-forums@pbcto7> |
| In reply to | #13590 |
Tim Slattery wrote:
>> I have a very simple command-line program in Eclipse, just a
>> System.out.println("Hello World"). It runs just fine in the IDE. So I
>> use File|Export|Export, and select "Runnable JAR file". A JAR is
>> created.
>>
>> And it doesn't work. I can double-click on it, or I can call it from a
>> command line. I get nothing. No "Hello world", no error message, no
>> nothing. What have I missed?
>
> More info:
> Here's the class:
>
>
> public class Main {
> public static void main(String[] args)
> {
> System.out.println("Here I am!");
> try
> {
> SimpleDateFormat sdf = new
> SimpleDateFormat("MM/dd/yyyy");
> sdf.setLenient(false);
> Date mydate = sdf.parse("2/29/1900");
> System.out.println("Good date: " + mydate.toString());
> }
> catch (ParseException ex)
> {
> System.out.println("ParseException: " +
> ex.getMessage());
> }
>
> }
>
> /* (non-Java-doc)
> * @see java.lang.Object#Object()
> */
> public Main() {
> super();
> }
>
> I export "Main.jar". To invoke from the command line, I type
> "Main.jar". Nothing but a command prompt. I have jedit installed. If I
> go to its directory and type "jedit.jar", it jumps right up. Therefore
> I assume that the JRE can be found.
"Main.jar" is not an executable, so it won't execute unless you give it one:
java -jar Main.jar
Show us the manifest, please?
Did you tell Windows to associate JAR files with the "java -jar" command, as "markspace" suggested?
What happens if you have a Word doc, say "foo.doc", and you type "foo.doc" at the command line?
--
Lew
[toc] | [prev] | [next] | [standalone]
| From | "John B. Matthews" <nospam@nospam.invalid> |
|---|---|
| Date | 2012-04-16 21:06 -0400 |
| Message-ID | <nospam-101416.21061216042012@news.aioe.org> |
| In reply to | #13592 |
In article <27365251.1727.1334611607107.JavaMail.geo-discussion-forums@pbcto7>, Lew <lewbloch@gmail.com> wrote: > "Main.jar" is not an executable, so it won't execute unless you give it one: > > java -jar Main.jar > > Show us the manifest, please? Tim: If you're not sure about the manifest, this utility will display your JAR's manifest, as built: <http://sites.google.com/site/drjohnbmatthews/manifesto> -- John B. Matthews trashgod at gmail dot com <http://sites.google.com/site/drjohnbmatthews>
[toc] | [prev] | [next] | [standalone]
| From | Knute Johnson <nospam@knutejohnson.com> |
|---|---|
| Date | 2012-04-16 14:35 -0700 |
| Message-ID | <jmi3bs$ifg$1@dont-email.me> |
| In reply to | #13590 |
On 4/16/2012 1:34 PM, Tim Slattery wrote:
> Tim Slattery<Slattery_T@bls.gov> wrote:
>
>> I must be doing something stupid.
>>
>> I have a very simple command-line program in Eclipse, just a
>> System.out.println("Hello World"). It runs just fine in the IDE. So I
>> use File|Export|Export, and select "Runnable JAR file". A JAR is
>> created.
>>
>> And it doesn't work. I can double-click on it, or I can call it from a
>> command line. I get nothing. No "Hello world", no error message, no
>> nothing. What have I missed?
>
> More info:
> Here's the class:
>
>
> public class Main {
> public static void main(String[] args)
> {
> System.out.println("Here I am!");
> try
> {
> SimpleDateFormat sdf = new
> SimpleDateFormat("MM/dd/yyyy");
> sdf.setLenient(false);
> Date mydate = sdf.parse("2/29/1900");
> System.out.println("Good date: " + mydate.toString());
> }
> catch (ParseException ex)
> {
> System.out.println("ParseException: " +
> ex.getMessage());
> }
>
> }
>
> /* (non-Java-doc)
> * @see java.lang.Object#Object()
> */
> public Main() {
> super();
> }
>
> I export "Main.jar". To invoke from the command line, I type
> "Main.jar". Nothing but a command prompt. I have jedit installed. If I
> go to its directory and type "jedit.jar", it jumps right up. Therefore
> I assume that the JRE can be found.
>
You are missing something here, that can't compile as it is. Try
compiling from the command line.
javac Main.java
and if that produces no errors, then run it with
java Main
--
Knute Johnson
[toc] | [prev] | [next] | [standalone]
| From | markspace <-@.> |
|---|---|
| Date | 2012-04-16 14:51 -0700 |
| Message-ID | <jmi48t$nsp$1@dont-email.me> |
| In reply to | #13590 |
On 4/16/2012 1:34 PM, Tim Slattery wrote:
> I export "Main.jar". To invoke from the command line, I type
> "Main.jar". Nothing but a command prompt. I have jedit installed. If I
> go to its directory and type "jedit.jar", it jumps right up. Therefore
> I assume that the JRE can be found.
OK, I tried it and I get the same behavior. BTW, this is what I mean
when I ask "show us the command line":
C:\Users\Brenden\Dev\proj\hw\dist>hw.jar
C:\Users\Brenden\Dev\proj\hw\dist>java -jar hw.jar
Hello world!
C:\Users\Brenden\Dev\proj\hw\dist>
That's cut-and-paste directly from my window on my computer. It's easy
to do, saves typing, and most importantly avoids typos when you're
trying to ask a technical question. Learn how to do it (use Google).
So I tried it with a new GUI app I made (just shows a dialog box with
"Hello World!") and that displays the dialog, but there's still no
console output. So I'm sure I have the file association set, and
further I'm still seeing the same behavior as you. I'm guessing this is
Microsoft interacting poorly with other vendors' products, and leave it
at that. File a bug report if you believe that will help. Meanwhile,
just use the "java -jar" command like I did above.
For others who might like to test this, here is the GUI test version:
package hwgui;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
/**
*
* @author Brenden
*/
public class Hwgui
{
public static void main( String[] args )
{
SwingUtilities.invokeLater( new Runnable()
{
public void run()
{
JOptionPane.showMessageDialog( null, "Hello World!");
}
} );
System.out.println( "Hello World!" );
}
}
[toc] | [prev] | [next] | [standalone]
| From | markspace <-@.> |
|---|---|
| Date | 2012-04-16 15:00 -0700 |
| Message-ID | <jmi4q0$qvi$1@dont-email.me> |
| In reply to | #13595 |
On 4/16/2012 2:51 PM, markspace wrote:
> System.out.println( "Hello World!" );
System.console().printf( "console-Hello World!" );
I added a second line after this to print out to the system console as
shown, and still no output. Now I'm somewhat aggrieved.
[toc] | [prev] | [next] | [standalone]
| From | Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> |
|---|---|
| Date | 2012-04-17 08:31 +0000 |
| Message-ID | <slrnjoqaje.kvi.avl@gamma.logic.tuwien.ac.at> |
| In reply to | #13595 |
markspace <-@> wrote: > C:\Users\Brenden\Dev\proj\hw\dist>hw.jar > > C:\Users\Brenden\Dev\proj\hw\dist>java -jar hw.jar > Hello world! > > C:\Users\Brenden\Dev\proj\hw\dist> I don't have a Windows-PC at hand, but I'd bet that: < C:\Users\Brenden\Dev\proj\hw\dist>javaw -jar hw.jar < < C:\Users\Brenden\Dev\proj\hw\dist> and that "javaw.exe" is registered as the default-handler for .jar (mind the extra "w" in the javaw command) PS: If the jarfile is just for your own use and you need it as a console- app, then you could rename it to hw.blah, and register java -jar as handler for .blah files. Once you start making GUI-apps, you just leave them as hw.jar (i.e. no longer rename them to hw.blah)
[toc] | [prev] | [next] | [standalone]
| From | markspace <-@.> |
|---|---|
| Date | 2012-04-17 07:35 -0700 |
| Message-ID | <jmjv3v$qmj$1@dont-email.me> |
| In reply to | #13608 |
On 4/17/2012 1:31 AM, Andreas Leitgeb wrote: > and that "javaw.exe" is registered as the default-handler for .jar I think you've got it. I just tried javaw on the command line and it works exactly the same as the default handler. I can't see what program Windows is using as the default (it only shows me a pretty icon) but I bet it's javaw. There was something tickling my brain as I was trying this out, but I didn't quite make the connection that javaw was being used as the handler, not java. Thanks for point that out.
[toc] | [prev] | [next] | [standalone]
| From | Lew <lewbloch@gmail.com> |
|---|---|
| Date | 2012-04-16 15:51 -0700 |
| Message-ID | <29862773.2344.1334616706236.JavaMail.geo-discussion-forums@pbvs10> |
| In reply to | #13590 |
Tim Slattery wrote:
> More info:
> Here's the class:
>
>
> public class Main {
> public static void main(String[] args)
> {
> System.out.println("Here I am!");
> try
> {
> SimpleDateFormat sdf = new
> SimpleDateFormat("MM/dd/yyyy");
> sdf.setLenient(false);
> Date mydate = sdf.parse("2/29/1900");
There was no such date, you know.
> System.out.println("Good date: " + mydate.toString());
> }
> catch (ParseException ex)
> {
> System.out.println("ParseException: " +
> ex.getMessage());
> }
>
> }
>
> /* (non-Java-doc)
> * @see java.lang.Object#Object()
> */
> public Main() {
> super();
> }
You don't need to specify that constructor, as it will be generated for you, and you certainly never need to call the no-argument 'super()'.
You're missing a closing curly brace.
> I export "Main.jar". To invoke from the command line, I type
> "Main.jar". Nothing but a command prompt. I have jedit installed. If I
> go to its directory and type "jedit.jar", it jumps right up. Therefore
> I assume that the JRE can be found.
What happens if you use the "java -jar" command?
--
Lew
[toc] | [prev] | [next] | [standalone]
| From | Tim Slattery <Slattery_T@bls.gov> |
|---|---|
| Date | 2012-04-17 08:56 -0400 |
| Message-ID | <41qqo71am9puku78uq1gc8rujn65lm0v0c@4ax.com> |
| In reply to | #13599 |
Lew <lewbloch@gmail.com> wrote:
>> Date mydate = sdf.parse("2/29/1900");
>
>There was no such date, you know.
I know. This started as a little test to see how SimpleDateFormat
would handle a non-existent date. I don't have a lot of experience
with Eclipse, so I then tried to see if I could run it outside of the
IDE.
--
Tim Slattery
Slattery_T@bls.gov
[toc] | [prev] | [next] | [standalone]
| From | Tim Slattery <Slattery_T@bls.gov> |
|---|---|
| Date | 2012-04-17 10:49 -0400 |
| Message-ID | <9g0ro7dmfsd0pdcdmrb9cgrk77agh2e4jh@4ax.com> |
| In reply to | #13590 |
Tim Slattery <Slattery_T@bls.gov> wrote:
>Tim Slattery <Slattery_T@bls.gov> wrote:
>
>>I must be doing something stupid.
>>
>>I have a very simple command-line program in Eclipse, just a
>>System.out.println("Hello World"). It runs just fine in the IDE. So I
>>use File|Export|Export, and select "Runnable JAR file". A JAR is
>>created.
>>
>>And it doesn't work. I can double-click on it, or I can call it from a
>>command line. I get nothing. No "Hello world", no error message, no
>>nothing. What have I missed?
>
>More info:
>Here's the class:
>
>
>public class Main {
> public static void main(String[] args)
> {
> System.out.println("Here I am!");
> try
> {
> SimpleDateFormat sdf = new
>SimpleDateFormat("MM/dd/yyyy");
> sdf.setLenient(false);
> Date mydate = sdf.parse("2/29/1900");
> System.out.println("Good date: " + mydate.toString());
> }
> catch (ParseException ex)
> {
> System.out.println("ParseException: " +
>ex.getMessage());
> }
>
> }
>
> /* (non-Java-doc)
> * @see java.lang.Object#Object()
> */
> public Main() {
> super();
> }
>
>I export "Main.jar". To invoke from the command line, I type
>"Main.jar". Nothing but a command prompt. I have jedit installed. If I
>go to its directory and type "jedit.jar", it jumps right up. Therefore
>I assume that the JRE can be found.
It looks like the problem is not that the program doesn't run, but
that the output from "System.out.println" is being written on the
wind. I included code to write a small file, and that file appears
when I double-click the jar file. So the program runs, but where is
the Standard Output file that System.out.println is supposed to write
to?
I could believe that it's on a console window that vanishes
immediately when I start it be double-clicking it. But when I open a
command window, navigate to the jar's directory and type "main.jar",
the exact same thing happens. The file is created, but the System.out
output is nowhere to be seen.
--
Tim Slattery
Slattery_T@bls.gov
[toc] | [prev] | [next] | [standalone]
| From | markspace <-@.> |
|---|---|
| Date | 2012-04-17 07:57 -0700 |
| Message-ID | <jmk0d4$25a$1@dont-email.me> |
| In reply to | #13613 |
On 4/17/2012 7:49 AM, Tim Slattery wrote: > It looks like the problem is not that the program doesn't run, but > that the output from "System.out.println" is being written on the > wind. Did you read the discussion above about "javaw"?
[toc] | [prev] | [next] | [standalone]
| From | Tim Slattery <Slattery_T@bls.gov> |
|---|---|
| Date | 2012-04-18 09:06 -0400 |
| Message-ID | <40fto71fe0dlmdr17ec02bme5m4mb4s91k@4ax.com> |
| In reply to | #13614 |
markspace <-@.> wrote: >On 4/17/2012 7:49 AM, Tim Slattery wrote: > >> It looks like the problem is not that the program doesn't run, but >> that the output from "System.out.println" is being written on the >> wind. > > >Did you read the discussion above about "javaw"? You're right, I made my post before seeing the others. I wasn't aware of "java.exe" vs "javaw.exe". Thanks all for pointing it out. -- Tim Slattery Slattery_T@bls.gov
[toc] | [prev] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2012-04-17 04:24 -0700 |
| Message-ID | <8mkqo7tsab31hrgrdr38la3s24hvc0s03e@4ax.com> |
| In reply to | #13586 |
On Mon, 16 Apr 2012 14:46:47 -0400, Tim Slattery <Slattery_T@bls.gov> wrote, quoted or indirectly quoted someone who said : >And it doesn't work. I can double-click on it, or I can call it from a >command line. I get nothing. No "Hello world", no error message, no >nothing. What have I missed? see http://mindprod.com/jgloss/jar.html Associate java.exe not javaw.exe or you will not see any output. -- 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] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web