This discussion is archived
8 Replies Latest reply: Jul 1, 2009 12:41 PM by 843810 RSS

import "jh.jar" to my application

843810 Newbie
Currently Being Moderated
I did a litle help with JavaHelp for my application and when i move to another computer the help will not display because it can not find the HelpSet class. On my PC a have the jar file "jh.jar" in my classpath, but I want to import it to my application but I don`t know how.

Can anyone know how to do this?
  • 1. Re: import "jh.jar" to my application
    843810 Newbie
    Currently Being Moderated
    You should add the jh.jar (or jhbasic.jar, depending on what you need) to your classpath.
    How are you launching the app?
    If it's launched with a simple java (or javaw) command just put the jar in the same directory and add args -cp ./jh.jar
    If the main class is declared in the manifest and you're simply double-clicking the jar you should use the Classpath attribute in the manifest file (in this case I guess you can put jh.jar in the jar itself).
    By the way (and in order for you to look at the proper documentation), this is not a JH problem, it's a simple Java classpath problem.

    Bye.
  • 2. Re: import "jh.jar" to my application
    843810 Newbie
    Currently Being Moderated
    Thank you for replying! On my PC the "jh.jar" file it is on the classpath, but when i move with the application on another computer i have to put the file "jh.jar" in the classpath in order to view the help.

    I was thinking to import that file in my application so that not everytime to put in the classpath on each computer i run the application. These 3 classes i use it from the "jh.jar":
    import javax.help.CSH;
    import javax.help.HelpBroker;
    import javax.help.HelpSet;
    but if the jh.jar is not in the classpath i get an exception. How do import those classes directly from the jar file, which is in my application folder?

    Calin.
  • 3. Re: import "jh.jar" to my application
    793415 Pro
    Currently Being Moderated
    >
    Thank you for replying!>
    Thank you for carefully reading the replies, and answering the questions of the people trying to help you. Oh, wait a second, you were asked +"How are you launching the app?"+ and I do not see the answer to that anywhere.

    Are you launching the application
    1) By double clicking the Jar?
    2) With a script/bat file?
    3) Using Java Web Start?
    4) Something else?
  • 4. Re: import "jh.jar" to my application
    843810 Newbie
    Currently Being Moderated
    Sorry....by click in the help button:
    try
         {
              URL hsURL = Main_Server.class.getResource("/Help/BackupTool.hs");                         
              hs = new HelpSet(null,hsURL);
         }
         catch (Exception ex) 
         {
              ex.printStackTrace();
              return;
         }
         hb = hs.createHelpBroker();
         new CSH.DisplayHelpFromSource(hb);
         hb.setSize(new Dimension(1024,768));                    
         hb.setCurrentID("main");
         hb.setDisplayed(true);     
    Edited by: Calin on Jun 30, 2009 9:40 PM
  • 5. Re: import "jh.jar" to my application
    843810 Newbie
    Currently Being Moderated
    We asked how you're launching the app, not the help.
    You talk about moving to another computer like you're bringing it on a USB-key, this takes us to the next big question: how are you distributing the app (if you are)?
    Anyway: those 3 classes you mentioned use many other JavaHelp classes, you can't possibly think including them in your jar will make your code run. How new are you to java? The 'over an year experience' I'd be guessing by your registration date should include basic classpath issues.

    Last (but definitively not least): according to the JavaHelp license you can redistribute jars but I don't think you can repackage classes as you like.

    Bye.

    PS: you've been told your question is border-line (meaning it's almost OT) and you've been given the right perspective on it, still you'd rather ask for more than google for something. What about adding dukes if you really wanna keep it alive?
  • 6. Re: import "jh.jar" to my application
    843810 Newbie
    Currently Being Moderated
    First of all my english is not so good! My fault for not understanding.

    I made my application a jar executable and run it (if this is what you want), and when click on the help button i get an exception because the HelpSet class is not found. I know it is not found because it is not in the classpath the file "jh.jar".

    I can say i am a beginner to java, but i know that class is needing other classes from that jar file.

    I was wondering if I can use that jar "jh.jar" in my application, instead of put it in the classpath to show the help. In other words to put it in the jar file (my application which is an executable jar) and call it from there. I think you got the ideea!

    Cheers!
  • 7. Re: import "jh.jar" to my application
    793415 Pro
    Currently Being Moderated
    >
    ...
    I made my application a jar executable and run it (if this is what you want),..>
    Not quite as much detail as I wanted, but.. let us cut to another question.

    Do you have (or can you get) a web site to distribute your code? If so, a good way to deploy it to users is using Java Web Start.

    (Further, if you distribute using webstart, there is another benefit in that you already have the attention of 2 people who can design or debug a webstart based launch for this application, and it's help files, and JavaHelp).
  • 8. Re: import "jh.jar" to my application
    843810 Newbie
    Currently Being Moderated
    Quoting myself:
    If the main class is declared in the manifest and you're simply double-clicking the jar you should use the Classpath attribute in the manifest file (in this case I guess you can put jh.jar in the jar itself).

    Googling out, it looks like you actually can't put a jar inside a jar (I thought you could cause you can put a jar in a war or an ear, my fault).
    Event though this looks different (at a glance, didn't go deep in it).
    Anyhow, according to the [sun jar specs|http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html] (that is the proper docs I kept mentioning):
    ◦Class-Path :
    
    The value of this attribute specifies the relative URLs of the extensions or libraries that this application or extension needs. URLs are separated by one or more spaces. The application or extension class loader uses the value of this attribute to construct its internal search path.
    So you should be able to try something like Class-Path: jar:MyJarName.jar!/jh.jar (and probably a lot of easier url like the ones in the over-mentioned thread).
    I never did it, never tried, don't mean to and think distribution should be solved with distribution techniques (like JWS or a simple zip file).
    If you want me to spend time on this instead of you and keep posting to the wrong forum (this is now officially OT), please add dukes (10 would be just fine).