Launch a .CHM File From Inside the JAR

Is it possible to launch a .CHM file (help file) or any other file for that matter from inside a JAR file using Runtime.getRuntime().exe()? If it's not possible with that command is it possible at all? Thanks in advance.

[228 byte] By [drawimagea] at [2007-11-27 11:50:34]
# 1

Anything can be done with native code.

Java can call any native code.

Therefore...

Runtime will work and so will the Java 6 Desktop API.

http://java.sun.com/javase/6/docs/api/java/awt/Desktop.html

TuringPesta at 2007-7-29 18:32:20 > top of Java-index,Java Essentials,Java Programming...
# 2

Thank you so much for your help. Your advice worked perfectly.

drawimagea at 2007-7-29 18:32:20 > top of Java-index,Java Essentials,Java Programming...
# 3

I actually just hit a problem with that. When I try to run that command from the JAR file and not the editor it throws an IOException saying "Access is denied." Here is the code I used: URL helpUrl = getClass().getResource("/com/test/help_file.chm");

try {

Desktop.getDesktop().browse(helpUrl.toURI());

} catch (IOException ex) {

ex.printStackTrace();

} catch (URISyntaxException ex) {

ex.printStackTrace();

}

Any suggestions?

drawimagea at 2007-7-29 18:32:20 > top of Java-index,Java Essentials,Java Programming...
# 4

Replace this line

URL helpUrl = getClass().getResource("/com/test/help_file.chm");

with this

URL helpUrl = this.getClass().getResource("/com/test/help_file.chm");

ChuckBinga at 2007-7-29 18:32:20 > top of Java-index,Java Essentials,Java Programming...
# 5

It gives the same error. I thought the "this" was implied with the way I wrote it.

drawimagea at 2007-7-29 18:32:20 > top of Java-index,Java Essentials,Java Programming...
# 6

Post (copy) the error message and associated text, and the portion of the program that surrounds the line it's pointing at.

Identify which line is the one being pointed at.

Post the different commands that you use to run the program, and which one works and which one fails.

ChuckBinga at 2007-7-29 18:32:20 > top of Java-index,Java Essentials,Java Programming...
# 7

Here is the stacktrace:

java.io.IOException: Failed to open jar:file:/C:/Test/dist/test_file.jar!/com/test/help_file.chm. Error message: Access is denied.

at sun.awt.windows.WDesktopPeer.ShellExecute(Unknown Source)

at sun.awt.windows.WDesktopPeer.browse(Unknown Source)

at java.awt.Desktop.browse(Unknown Source)

at com.test.Test.jLabelHelpMouseClicked(Test.java:486)

at com.test.Test.access$300(Test.java:43)

at com.test.Test$4.mouseClicked(Test.java:181)

at java.awt.Component.processMouseEvent(Unknown Source)

at javax.swing.JComponent.processMouseEvent(Unknown Source)

at java.awt.Component.processEvent(Unknown Source)

at java.awt.Container.processEvent(Unknown Source)

at java.awt.Component.dispatchEventImpl(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Window.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.run(Unknown Source)

The code I am using is the code that I previously posted with the "this" in front of getClass(). It fails at Desktop.getDesktop().browse(helpUrl.toURI()); Throwing an IOException. The program is GUI, I have no commands to run it, this particular code fires on a mouseClickEvent.

drawimagea at 2007-7-29 18:32:20 > top of Java-index,Java Essentials,Java Programming...
# 8

The Desktop.browse method says it produces:

[an] IOException - if the user default browser is not found, or it fails to be launched, or the default handler application failed to be launched

I assume whatever the "default handler application" is for .chm files, it can't open a help.chm that's within a jar. Items in a jar are not files, insofar as the os is concerned, and probably the program trying to open the help.chm is an os program.

ChuckBinga at 2007-7-29 18:32:20 > top of Java-index,Java Essentials,Java Programming...
# 9

Is it possible to temporarily extract the file from the jar while it is being run?

drawimagea at 2007-7-29 18:32:20 > top of Java-index,Java Essentials,Java Programming...
# 10

Typically, resources (such as help files) that are required by the application's os-programs are extracted from jar files when the application is installed. (Note that I say os-program, not Java program - correctly configured, Java programs can operate with resources that are in jars.)

You could extract the help file at some later time, but why, instead of at installation?

ChuckBinga at 2007-7-29 18:32:20 > top of Java-index,Java Essentials,Java Programming...
# 11

Currently I am doing it at installation; however, I was hoping to be able to put the help file in the jar file to make it more portable. As of right now, the only reason I have an installer is the help file. I was hoping to be able to skip a step. Anyway, thank you for your help and time; I think I will leave it like it is.

drawimagea at 2007-7-29 18:32:20 > top of Java-index,Java Essentials,Java Programming...