Program can't find class in .jar file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PaperPilot
    New Member
    • Nov 2006
    • 46

    #1

    Program can't find class in .jar file

    I have a Java program that is deployed as a .jar file in which is another .jar file with the mysql library. Here is the appropriate section of code:

    Code:
       /**
    	* Makes the connection to the database.
    	*/
       protected static Connection makeConnection()
       {
    	  try
    	  {
    		 Class.forName("org.gjt.mm.mysql.Driver");
    
    		 database = DriverManager.getConnection(
    			   dataBaseName, dbAccessUserId, dbAccessPwd);
    	  }
    
    	  catch (SQLException sqle)
    	  {
    		 System.out
    			   .println("Error while connection attempt!");
    		 sqle.printStackTrace();
    	  }
    	  catch (ClassNotFoundException e)
    	  {
    		 System.out.println("Jdbc Driver not found: "
    			   + e.getMessage());
    		 e.printStackTrace();
    	  }
    
    	  return database;
       }
    When I execute the .jar file, I get this error message and trace:

    Jdbc Driver not found: org.gjt.mm.mysq l.Driver
    java.lang.Class NotFoundExcepti on: org.gjt.mm.mysq l.Driver
    at java.net.URLCla ssLoader$1.run( Unknown Source)
    at java.security.A ccessController .doPrivileged(N ative Method)
    at java.net.URLCla ssLoader.findCl ass(Unknown Source)
    at java.lang.Class Loader.loadClas s(Unknown Source)
    at sun.misc.Launch er$AppClassLoad er.loadClass(Un known Source)
    at java.lang.Class Loader.loadClas s(Unknown Source)
    at java.lang.Class Loader.loadClas sInternal(Unkno wn Source)
    at java.lang.Class .forName0(Nativ e Method)
    at java.lang.Class .forName(Unknow n Source)
    at gov.nasa.jsc.fc od.asp3.gII_sim ulator.user_int erface.jdbc.GII DatabaseM
    Some how the code in the main .jar file is not finding the Driver class embedded in the .jar file containing the mysql library.

    Does anyone know how to access this library .jar file?

    Thanks in advance.
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by PaperPilot
    Does anyone know how to access this library .jar file?
    Yep, simply mention that jar file (and the path to it) in your classpath variable.

    kind regards,

    Jos

    Comment

    • PaperPilot
      New Member
      • Nov 2006
      • 46

      #3
      Originally posted by JosAH
      Yep, simply mention that jar file (and the path to it) in your classpath variable.

      kind regards,

      Jos
      I have tried every possible form of the CLASSPATH system variable including the path to another version of mm_mysql-2_0_4-bin.jar to no avail. My problem is something other than the CLASSPATH.

      Thanks.

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by PaperPilot
        I have tried every possible form of the CLASSPATH system variable including the path to another version of mm_mysql-2_0_4-bin.jar to no avail. My problem is something other than the CLASSPATH.

        Thanks.
        If it is another problem then you didn't spell "org.gjt.mm.mys ql.Driver" correctly.
        I can't tell from here; the jvm simply searches all lasspath entries for a fully
        qualified class name. If the class is stored on the file system directly then the
        classloader assumes the package components to be directories descending
        from one of the classpath entries. Otherwise, when you mentioned a .jar file as
        a classpath entry, the classloader seaches the jar for your fully qualified class
        name.

        A last option is that your classpath is correct and you spelt the name of the class
        correctly but the class simply isn't there.

        kind regards,

        Jos

        Comment

        • praveen2gupta
          New Member
          • May 2007
          • 200

          #5
          Hi
          Put the driver jar file library.jar in the folder of your code. Now create a jar file of your code and write also the name of library.jar along with the classes name.

          The jar file can contain another jar file within it.

          Comment

          Working...