problem running an executable jar file - shows up as ZIP file

hi all,

i am having a problem running an executable jar file at a click. i have java 1.5 installed, javac and java work fine. I am able to run the jar using java -jar <jar file name>

the jar file opens as a zip folder. all the files are in order and there is no corruption whatsoever

i am not sure what the problem is.

i would appreciate some guidance about this

[399 byte] By [dunstona] at [2007-10-2 0:28:16]
# 1
Check your file associations. (in your OS, not in the java level)
paulcwa at 2007-7-15 16:42:45 > top of Java-index,Java Essentials,Java Programming...
# 2
Hi I am not clear what you mean by file associations. Would appreciate further guidance
dunstona at 2007-7-15 16:42:45 > top of Java-index,Java Essentials,Java Programming...
# 3

> Hi I am not clear what you mean by file associations.

> Would appreciate further guidance

The Windows operating system (maybe other OS's too) associate file extensions with applications. That's what makes it decide what to execute when you double-click the Something.jar file. Windows keeps such information in the Windows registry. It's a complicated database and I don't know what the exact keys and values to tell you to look for, but you can look at the registry by running the regedit tool that comes with Windows.

Probably rather than hand-edit the registry, you need to figure out what install-package you are supposed to run to get it to do that registry edit for you.

warnerjaa at 2007-7-15 16:42:45 > top of Java-index,Java Essentials,Java Programming...
# 4

You don't have to update the registry to change file associations on M$-Windows. Or at least, if that's what you're doing there's a straightforward (relatively straightforward given that it's Windows) way of changing it.

If you open a filesystem Explorer window (as opposed to an Internet Explorer window, although maybe it works there too) then under, I think, the Tools menu, there's a "Folder Options" menu item. Then under there you can click or select or something to get to a list of filename extensions and what applications they map to. It's a pain, but what are you going to do? Gates and Ballmer have a monopoly. Now drop 'em and bend over.

Normally, when you install a JRE the file association is usually set, but maybe it got un-set. Again: Windows.

In any event this is worth checking regardless of the system you're using, if clicking the jar doesn't work right.

paulcwa at 2007-7-15 16:42:45 > top of Java-index,Java Essentials,Java Programming...
# 5

here's another method:

1) open windows explorer

2) navigate to a directory that includes a .jar file

3) right click on the jar file and select the properties option

4) in the properties window that is displayed, note the "opens with" label

5) if it does not have "javaw" next to it then:

6)click on the button labeled "Change"

7)a dialog appears that asks "Click on the program that you want to ....."

8)find and select "javaw"

walker

p.s. Thank you paulcw for excellent response.

walker8a at 2007-7-15 16:42:45 > top of Java-index,Java Essentials,Java Programming...
# 6

Hi Thanks much for your response. I corrected the problem as u suggested

I am facing yet another problem

My jar file created by Netbeans in project/dist folder does not execute at all.

On double clicking it, it opens up a huge blank panel and nothing else. The screen is completely blank. The application uses a lot of Swing and should paint multiple components on the screen. The CPU usage shoots up to 100%. I have to force-shut-down my window's machine and start it again.

However this application works fine when i manually create the jar in the same folder as the class files. I am manually compiling the source files and keeping the generated class files in the same directory as the class files I am using THESE class files to create the jar using "jar cmf <mainfest.mf> <jar file name> *.class

I do not face this problem with any of the other Java projects which are created using Netbeans.

This application predominantly uses Swing and uses an JDBC-ODBC to read data from an Access Database and provides a user interface to manipulate this data.

Again, when I copy this jar to another location, such as my desktop, and try to run it, it opens up and paints one big panel and nothign else. Its behaviour becomes the same as the one created by Netbeans.

I am not using any packages in this application. It is a set of 14 class files, all of which create panels, frames, checkboxes, radio buttons, etc...to manipulate data from the ms-access database.

I would GREATLY appreciate any tips regarding how to create a DISTRIBUTABLE, EXECUTABLE jar frm these 14 source files which can be run from any location. I do not want to enforce any constraints on the user such copyign this jar into a specific directory and attempt creating a dos-batch file with the line 'java -jar C:/<jar file>'

A prompt response would be greatly appreciated

Thanks much in advance

Lals

dunstona at 2007-7-15 16:42:45 > top of Java-index,Java Essentials,Java Programming...
# 7
A Netbeans user can probably give better advice about this than I can.But I'd suggest creating an "Hello World!" GUI app in Netbeans and see if the same thing happens. If it happens with a very simple program, it'll probably be easier to isolate the problem.
paulcwa at 2007-7-15 16:42:45 > top of Java-index,Java Essentials,Java Programming...
# 8
Do you rely on files given by a relative path, such as configuration files, text bundles, or icons? Sounds a bit like you created a neverending loop around some part of your code which throws an exception that's silently swallowed.
quittea at 2007-7-15 16:42:45 > top of Java-index,Java Essentials,Java Programming...
# 9
Perhaps you need to add a few println() statements in your code to see what is happening. Then use java.exe vs javaw.exe to execute you jar file. The println()s on the console might tell you something.
A_Sailora at 2007-7-15 16:42:45 > top of Java-index,Java Essentials,Java Programming...
# 10

Hey, if you downloaded the jar file using windows you need to chage the extension name. Open cmd prompt, go to the directory and type dir, probably the extension is .zip, then you type rename nameOfOriginalFile.zip nameOfFinalFile.jar. This just happens on windows and it s very annoying, so try that.

-guto

gutorb4a at 2007-7-15 16:42:45 > top of Java-index,Java Essentials,Java Programming...
# 11

Hi all,

I am having a similar problem. I have a written a simple program in java with netbeans which copies files and folders from one location to another where the absolute path of both the source and destination directories is provided as input.

My problem is that when i double click on the jar file which is in the dist folder, nothing happens? Do jar files run on double click?

I have tried checking the paths as specified above.. i.e going to tools>folder options>file types... clicking on jar, then Advanced> Edit ...etc etc but everything looks perfect and is the same as specified above.

Please help on this issue

Riaz

@.Ra at 2007-7-15 16:42:45 > top of Java-index,Java Essentials,Java Programming...
# 12

> I have a written a simple program in java with netbeans which copies files and

> folders from one location to another where the absolute path of both the source

> and destination directories is provided as input.

The default behaviour in Windows is to use javaw.exe to launch the jar file. (See reply 5)

Now you don't say how the directories are input. If they are specified on the command line, then you have a problem because double clicking will never give you a chance to enter the directories.

If the directories are entered via System.in (including Scanner, Console and friends) then you also have a problem because the Windows javaw.exe suppresses the console.

What to do? (Assuming that installing a more tractable OS is not an option). Write a batch file (.bat) to launch your jar file using the java.exe executable with the -jar switch. Launched this way you will get to interact with System.in to enter the directories.

pbrockway2a at 2007-7-15 16:42:45 > top of Java-index,Java Essentials,Java Programming...