• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jar

 
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, i know how to create a jar file.

but when you create it, when you double click on it, does it automatically

execute the main class?

or do you have to modify the manifest file?

-Justin-
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, i figured how to make it "executable" through the command line,

but what about when you double click on the file itself, nothing happens.

what do i need to do to get it to open when i double click on it

-Justin
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The file "META-INF/MANIFEST.MF " in the jar file must contain a line like

Main-Class: com.justin.ClassName

and then your desktop has to be set up to associate JAR files with java.exe.
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok i changed the desktop to where it opens jar files with java.exe, but

and blank black box pops up and then goes away really fast...

why is that?

-Justin-
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have the class called AVerage.class

and i did

jar cfm Average.jar Manifest.txt AVerage.class.

and in the Manifest.txt

it says.

Main-Class: AVerage

-Justin-
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
help me plz
 
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Search this forum with keyword jar. I remember one of the bartenders here has written a series of articles regarding jar and related stuff.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A quick search through the FAQ finds this page, which has some hints and links to further information.

If it terminates quickly, then that probably means there was an uncaught exception. Try running it from the command line like "java -jar xyz.jar". Then you'll have a chance to see the stack trace of the exception.
[ May 03, 2006: Message edited by: Ulf Dittmer ]
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ok i changed the desktop to where it opens jar files with java.exe, but and blank black box pops up and then goes away really fast...


You should change the association so that Windows
uses javaw.exe to open the .jar file. (The difference
is that you don't get the console window.)

This is usually the default, but it might have got
changed somehow. You can right click on a .jar file
and choose "Open with..." to change the association.

Ernest's point about the manifest is important - otherwise
"nothing" will happen when you double click the .jar
file. Sometimes you actually want to see the console
output - for error messages when the program is starting,
or for debugging output that you print to System.out. One
way to achieve this is to run the program from the command
line with:
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah, it works fine in the command prompt

and tried to get javaw.exe to open it and the hour glass came up and that

was it....

i did everything right...

guess my comp sucks or something

-Justin-
 
Peter Brockway
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It might be a good idea to put a System.out.println("!!!") at the start of your main() method. You should be able to see this from the command prompt when you use the java -jar command. This will test that there is nothing wrong with the manifest.

When you say it works fine from the command prompt, what actually happens? I ask this because to be visible your program has to produce some non-console output (eg make a JFrame visible or whatever). What you are expecting to see is that running javaw.exe (via a double click) has exactly the same result as running java -jar (except for console output).

If the code is not too long perhaps you could post it.
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is what my mainfest file contains:



and here is the java file AVerage.java:



the program is very simple..

and when i do the: java -jar Average.jar, that works just fine,

the out put looks like this:



because i created my file like this: jar cmf Averagefest.txt Average.jar AVerage.class

all i want is for the command line to pop up when i double click on the
file..

or does it only work if you jar a applet?

thanks in advance

-Justin-
[ May 04, 2006: Message edited by: Justin Fox ]
 
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Peter Brockway gave you the answer as to why, reread it. You have no non-console output.
[ May 04, 2006: Message edited by: Rusty Shackleford ]
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and if the double click only works with a JFrame, can i display that

application in my own frame?

but still the the functionality that i want?

for example:

when i double click, my own JFrame pops up, but still has output inside it

like so:



and would the JFrame act just as a command prompt?

-Justin-
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you told me that he told me the answer, but it must have been a subliminal

message, because i didn't see an answer just assumtions(not to be an Ahole)

I have posted the code, and have asked my question about the JFrame thing.

i mean i understand that i have to have an applet or jframe for the double

click to work, but i still have my other question floating around.

waiting...

-Justin-
[ May 04, 2006: Message edited by: Justin Fox ]
 
Peter Brockway
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

you told me that he told me the answer, but it must have been a subliminal message, because i didn't see an answer just assumtions


Sorry, I may not have been very clear. But I think you've figured out that using javaw to run a .jar file is not good if your program relies on console input and output.

As an alternative you could write a short script (.bat or .cmd) file to launch your .jar file. For instance

;File: c:\AVerage.bat
"Program Files\Java\jdk1.5.0_06\bin\java" -jar AVerage.jar

is quite effective in running your program in a console window. (Note the lack of "w" in the command name). There is still a problem because the window closes before you can read the answer! One way around this is to add a prompt, "Press <Enter> to exit..." and read a line of input from the console before exiting.

(There may be other bugs in your program, but they don't have anything to do with running it as a .jar)

To address your other question: you could write your own Swing component that interacts textually with the user, but this is not easy. Probably it is better if you are writing a graphical application to do things graphically (use controls and dialog boxes to gather and display information). And if you are using Scanner, launch the .jar with a script as described above.

Do (continue to) ask if I'm being unclear. There's a bit of a time lag - I guess we're in different time zones.
[ May 05, 2006: Message edited by: Peter Brockway ]
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I made an applet and jar'd it and the double click works just fine.

thanks for all the help, i guess for my average class i'll have to make it

a GUI to be able to double click it and use it.

but all i would have to do is have labels,

one for the line "Enter Number to be Averaged: "

and then one for "Enter the "+count+" Number: " // then have a

JTextfield 't' for input.

then i could do :

int answer = Integer.parseInt(t.getText());
int sum = 0;
sum += answer;

and have some buttons, "add" and "average".

anyways, thanks again.

-Justin-
[ May 05, 2006: Message edited by: Justin Fox ]
 
Something must be done about this. Let's start by reading this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic