2

I'm making a Swing application that will only run on Windows and I want to package everything into a single .jar file. I want to include a .chm help file in the JAR and be able to launch it from clicking a JMenuItem marked "Help" or "Contents" (I already have a working understanding of creating AbstractAction subclasses). How can I programmatically open a .chm file from a JAR file?

SimonT
  • 2,219
  • 1
  • 18
  • 32
  • Maybe `Desktop#open()`? – trashgod Sep 02 '13 at 18:10
  • @trashgod I'm guessing you mean http://docs.oracle.com/javase/7/docs/api/java/awt/Desktop.html#open%28java.io.File%29. I suppose you would have to treat an `InputStream` as a `File` somehow. – SimonT Sep 02 '13 at 18:13

1 Answers1

4

Desktop provides an open() method. You'll probably have to retrieve the .chm as an and park it at a known location in the file system.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • 1
    Maybe if the OP distributes the `JAR` as a zip file, the jar and chm can be in the same directory and thus eliminating the need for embedded resource ? :) – An SO User Sep 02 '13 at 18:16
  • @Little Child, I was considering that, but there is the possibility that somebody will end up just taking the JAR with them and then missing the CHM. I suppose a slightly lazy workaround would be to copy the CHM to some place on disk if it can't be found at runtime, but I still want a one-file solution if possible. – SimonT Sep 02 '13 at 18:19
  • @LittleChild": Good idea. My only reservation would be mission creep on the _Windows only_ requirement. I'd at least leave hooks for a _strategy pattern_. – trashgod Sep 02 '13 at 18:21
  • @trashgod You mean create a cross-platform help file ? :) – An SO User Sep 02 '13 at 18:22
  • @LittleChild: I don't know if `.chm` can be made cross-platform; I usually load embedded HTML in a `JEditorPane`. Edit: OSX know locations [here](http://stackoverflow.com/a/14233171/230513). – trashgod Sep 02 '13 at 18:27
  • 1
    There are cross-platform viewers for CHM like these: http://en.wikipedia.org/wiki/Microsoft_Compiled_HTML_Help#Use_in_non-Windows_applications. – SimonT Sep 02 '13 at 18:52