Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Self-executing JAR

Reply
Thread Tools

Self-executing JAR

 
 
Andreas Leitgeb
Guest
Posts: n/a
 
      04-17-2012
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)

 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      04-17-2012
On Mon, 16 Apr 2012 14:46:47 -0400, Tim Slattery <(E-Mail Removed)>
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..
 
Reply With Quote
 
 
 
 
Tim Slattery
Guest
Posts: n/a
 
      04-17-2012
Lew <(E-Mail Removed)> 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
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
markspace
Guest
Posts: n/a
 
      04-17-2012
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.

 
Reply With Quote
 
Tim Slattery
Guest
Posts: n/a
 
      04-17-2012
Tim Slattery <(E-Mail Removed)> wrote:

>Tim Slattery <(E-Mail Removed)> 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
(E-Mail Removed)
 
Reply With Quote
 
markspace
Guest
Posts: n/a
 
      04-17-2012
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"?

 
Reply With Quote
 
Tim Slattery
Guest
Posts: n/a
 
      04-18-2012
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
(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
java -cp a.jar -jar b.jar => Works on Windows, not on Debian cyberco Java 4 02-14-2006 06:27 AM
jaas.jar, jta.jar jdbc-stdext.jar missing from jdk1.5 RPM muttley Java 0 10-20-2005 02:40 PM
Differences of xercesImpl.jar, xercesImpl-J.jar, dom3-xercesImpl.jar ? Arnold Peters Java 0 01-05-2005 10:59 PM
Differences of xercesImpl.jar, xercesImpl-J.jar, dom3-xercesImpl.jar ? Arnold Peters XML 0 01-05-2005 10:59 PM
Jar file cannot find main class - gfSetup.jar (0/1) James Alan Farrell Java 6 01-09-2004 12:40 PM



Advertisments