Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

classpath issue

Status
Not open for further replies.

YerMom

Programmer
Oct 3, 2006
127
US
Yes, it's the classic classpath problem.
I'm trying to run a small application on Windows XP using the following for a batch file:
Code:
echo off
cd D:\D_ProgramFiles\JavaHelp\MyStuff
java JavaHelpTest -classpath D:\D_ProgramFiles\JavaHelp\jh2.0\javahelp\lib\jhall.jar
pause

JavaHelpTest.class is indeed in the above directory, and jhall.jar is in the directory specified by the classpath argument. But I get the following output:

Code:
D:\D_ProgramFiles\JavaHelp\MyStuff>echo off
Exception in thread "main" java.lang.NoClassDefFoundError: javax/help/JHelp
Press any key to continue . . .

And jhall.jar does contain javax/help/JHelp.class

Below is the app:
Code:
// Import the javahelp files.
import javax.help.*;
import java.net.URL;
import javax.swing.*;
public class JavaHelpTest {
   public static void main(String args[]) {
      JHelp helpViewer = null;
      try {
         // Get the classloader of this class.
	      ClassLoader cl = JavaHelpTest.class.getClassLoader();
         // Use the findHelpSet method of HelpSet to create a URL referencing the helpset file.
         // Note that in this example the location of the helpset is implied as being in the same
         // directory as the program by specifying "jhelpset.hs" without any directory prefix,
         // this should be adjusted to suit the implementation.
	      URL url = HelpSet.findHelpSet(cl, "jhelpset.hs");
         // Create a new JHelp object with a new HelpSet.
         helpViewer = new JHelp(new HelpSet(cl, url));
         // Set the initial entry point in the table of contents.
         helpViewer.setCurrentID("Simple.Introduction");
	   } catch (Exception e) {
	      System.err.println("API Help Set not found");
     	}

      // Create a new frame.
      JFrame frame = new JFrame();
      // Set it's size.
      frame.setSize(500,500);
      // Add the created helpViewer to it.
      frame.getContentPane().add(helpViewer);
      // Set a default close operation.
      frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
      // Make the frame visible.
      frame.setVisible(true);
   }
}



What am I doing wrong?

Thanks.
 
I am very new to java but when you created the jar did you set the entry point in the manifest file.
 
kenanbr,

Thanks. I'm not sure that's applicable here because the jar file does not contain an application, it is really just a set of classes that Java help systems need.

Thanks again.
 
Oh, I see now. But is your 'JavaHelpTest' in the same CLASSPATH. If not include the path to 'JavaHelpTest' in CLASSPATH.
 
I believe that your java command should be like this (classpath before the class):

Code:
java -classpath D:\D_ProgramFiles\JavaHelp\jh2.0\javahelp\lib\jhall.jar JavaHelpTest

Alternatively you can remove the classpath option from the java command and add this in your batch file before the JAVA command:

Code:
 SET CLASSPATH=%CLASSPATH%;D:\D_ProgramFiles\JavaHelp\jh2.0\javahelp\lib\jhall.jar;.;

Nitin
 
Nitin,

Thanks. I changed the order and my bat file looks like this:
Code:
echo off
cd D:\D_ProgramFiles\JavaHelp\MyStuff

java -verbose -classpath D:\D_ProgramFiles\JavaHelp\MyStuff D:\D_ProgramFiles\JavaHelp\jh2_0\javahelp\lib\jhall.jar JavaHelpTest > runlog.txt 2>&1
pause


but now I'm getting the following error when I try to run the app:
Code:
java.lang.NoClassDefFoundError: D:\D_ProgramFiles\JavaHelp\jh2_0\javahelp\lib\jhall/jar

Java seems to be interpreting the dot in the .jar extension as something other than a file name. But I also see the following in the output:
Code:
[Opened D:\D_ProgramFiles\java\jdk1.5.0_06\jre\lib\rt.jar]
So I don't know why in one case Java has no problems opening a jar file (in the case of rt.jar) but with jhall.jar it gets confused.
 
Sorry, did not notice this earlier...try putting a semicolon after each of your classpath entries

Code:
java -verbose -classpath D:\D_ProgramFiles\JavaHelp\MyStuff[COLOR=red];[/color] D:\D_ProgramFiles\JavaHelp\jh2_0\javahelp\lib\jhall.jar[COLOR=red];[/color] JavaHelpTest > runlog.txt 2>&1

Nitin
 
I'm sad to say I never solved this problem. I created an Eclipse project instead. I would really like to know why my bat file solution does not work. Have any of you been able to compile/run the JavaHelpTest app I included above?

Thanks.
 
[0] Where do you get the referred jhelpset.hs? The functioning does not depend only on one .hs file but a whole complete set of components working together.

[1] I have no problem to make the program work if that part is set up correctly, sure together with the classpath etc.

[2] I would suggest you use one of the demos come directly with the download.
 
Well, the op is lacking response. That's fine. If they really want to know what is the problem with the bat file as well (rather than the java proper), I can say this.

[3]
>cd D:\D_ProgramFiles\JavaHelp\MyStuff
This is improper if you start in any drive other than d:
 
I was also waiting for the response, but anyway, a ClassNoDefFoundError is not an ClassNotFoundException, there may be other causes, as different versions for compiling and executing

Cheers,
Dian
 
Try and add current location to the classpath by letting the classpath start with -classpath .;D:\D_ProgramFi.....
 
Dian, nitin, cljen and tsuji,

My apologies for not responding sooner -- I had to divert my attention to another project.

Unfortunately I'll have to put this puzzle aside for now and focus on my work in Eclipse.

Thanks for your time and your responses.

My apologies.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top