NoClassDefFoundError - please help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NamelessNumberheadMan
    New Member
    • Jul 2007
    • 15

    NoClassDefFoundError - please help

    I'm using MyEclipse to make a quick one or two use jar utility file to connect to a database and run some updates. I can get everything to compile fine, and create the jar without an issue, but when I execute it from the command prompt I get a NoClassDefFound Error.

    Here is the stack trace:

    Exception in thread "main" java.lang.NoCla ssDefFoundError : com/microsoft/jdbc/sq
    lserver/SQLServerDriver
    at com.dbinterface .DatabaseAccess .execute(Databa seAccess.java:1 08)
    at com.dbinterface .DatabaseAccess .loadSqlfiles(D atabaseAccess.j ava:81)
    at com.dbinterface .DatabaseAccess .getFileList(Da tabaseAccess.ja va:39)
    at com.dbinterface .RunSqlScripts. main(RunSqlScri pts.java:24)

    This is the method where the error is thrown -

    Code:
    public void execute(StringBuffer sb)
    	{
    		Connection conn = null;
    		Statement stmt = null;
    		ResultSet rs = null;
    		
    		try{
    			DriverManager.registerDriver(new com.microsoft.jdbc.sqlserver.SQLServerDriver());
    			conn = DriverManager.getConnection(Constants.DATABASE_NAME, Constants.USERNAME, Constants.PASSWORD);
    			stmt = conn.createStatement();			
    			
    			stmt.execute(sb.toString());
    			
    			rs.close();
    			stmt.close();
    			conn.close();			
    			
    		}
    		catch(Exception e)
    		{
    			e.printStackTrace();
    		}		
    		finally
    		{
    			try{
    				if(null != rs)
    					rs.close();
    				if(null != stmt)
    					stmt.close();
    				if(null != conn)
    					conn.close();
    			}
    			catch(Exception e)
    			{
    				e.printStackTrace();
    			}
    		}
    	}
    All the forums I find ask about the classpaths so here is my .classpath file created by MyEclipse:

    [HTML]<?xml version="1.0" encoding="UTF-8"?>
    <classpath>
    <classpathent ry kind="src" path="src"/>
    <classpathent ry kind="con" path="org.eclip se.jdt.launchin g.JRE_CONTAINER "/>
    <classpathent ry exported="true" kind="lib" path="C:/temp/dbInterface/sqljdbc.jar"/>
    <classpathent ry exported="true" kind="lib" path="C:/temp/dbInterface/msbase.jar"/>
    <classpathent ry exported="true" kind="lib" path="C:/temp/dbInterface/mssqlserver.jar "/>
    <classpathent ry exported="true" kind="lib" path="C:/temp/dbInterface/msutil.jar"/>
    <classpathent ry kind="output" path="bin"/>
    </classpath>[/HTML]

    My jar file is located in C:/temp/dbInterface.

    This is what my MANIFEST.MF file contains:

    Manifest-Version: 1.0
    Main-Class: com.dbinterface .RunSqlScripts

    Please help. As far as I see my classpaths are correct. I'm not sure what to try from here.

    ------------UPDATE------------

    I just attempted adding the classpaths to my manifest so it would now look like:

    Manifest-Version: 1.0
    Class-Path: .;C:\temp\dbInt erface\msbase.j ar;C:\temp\dbIn terface\mssqlse rver.jar;C:\tem p\dbInterface\m sutil.jar;C:\te mp\dbInterface\ sqljdbc.jar
    Main-Class: com.dbinterface .RunSqlScripts


    Still didn't work. I quite desperate at this point.
    Last edited by NamelessNumberheadMan; Aug 2 '07, 02:56 PM. Reason: Attempted somthing Different - still failed
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by NamelessNumberh eadMan
    I'm using MyEclipse to make a quick one or two use jar utility file to connect to a database and run some updates. I can get everything to compile fine, and create the jar without an issue, but when I execute it from the command prompt I get a NoClassDefFound Error.

    Here is the stack trace:

    Exception in thread "main" java.lang.NoCla ssDefFoundError : com/microsoft/jdbc/sq
    lserver/SQLServerDriver
    at com.dbinterface .DatabaseAccess .execute(Databa seAccess.java:1 08)
    at com.dbinterface .DatabaseAccess .loadSqlfiles(D atabaseAccess.j ava:81)
    at com.dbinterface .DatabaseAccess .getFileList(Da tabaseAccess.ja va:39)
    at com.dbinterface .RunSqlScripts. main(RunSqlScri pts.java:24)

    This is the method where the error is thrown -

    Code:
    public void execute(StringBuffer sb)
    	{
    		Connection conn = null;
    		Statement stmt = null;
    		ResultSet rs = null;
    		
    		try{
    			DriverManager.registerDriver(new com.microsoft.jdbc.sqlserver.SQLServerDriver());
    			conn = DriverManager.getConnection(Constants.DATABASE_NAME, Constants.USERNAME, Constants.PASSWORD);
    			stmt = conn.createStatement();			
    			
    			stmt.execute(sb.toString());
    			
    			rs.close();
    			stmt.close();
    			conn.close();			
    			
    		}
    		catch(Exception e)
    		{
    			e.printStackTrace();
    		}		
    		finally
    		{
    			try{
    				if(null != rs)
    					rs.close();
    				if(null != stmt)
    					stmt.close();
    				if(null != conn)
    					conn.close();
    			}
    			catch(Exception e)
    			{
    				e.printStackTrace();
    			}
    		}
    	}
    All the forums I find ask about the classpaths so here is my .classpath file created by MyEclipse:

    [HTML]<?xml version="1.0" encoding="UTF-8"?>
    <classpath>
    <classpathent ry kind="src" path="src"/>
    <classpathent ry kind="con" path="org.eclip se.jdt.launchin g.JRE_CONTAINER "/>
    <classpathent ry exported="true" kind="lib" path="C:/temp/dbInterface/sqljdbc.jar"/>
    <classpathent ry exported="true" kind="lib" path="C:/temp/dbInterface/msbase.jar"/>
    <classpathent ry exported="true" kind="lib" path="C:/temp/dbInterface/mssqlserver.jar "/>
    <classpathent ry exported="true" kind="lib" path="C:/temp/dbInterface/msutil.jar"/>
    <classpathent ry kind="output" path="bin"/>
    </classpath>[/HTML]

    My jar file is located in C:/temp/dbInterface.

    This is what my MANIFEST.MF file contains:

    Manifest-Version: 1.0
    Main-Class: com.dbinterface .RunSqlScripts

    Please help. As far as I see my classpaths are correct. I'm not sure what to try from here.

    ------------UPDATE------------

    I just attempted adding the classpaths to my manifest so it would now look like:

    Manifest-Version: 1.0
    Class-Path: .;C:\temp\dbInt erface\msbase.j ar;C:\temp\dbIn terface\mssqlse rver.jar;C:\tem p\dbInterface\m sutil.jar;C:\te mp\dbInterface\ sqljdbc.jar
    Main-Class: com.dbinterface .RunSqlScripts


    Still didn't work. I quite desperate at this point.
    In which .jar file is the class com.microsoft.j dbc.sqlserver.S QLServerDriver stored?
    That's the class that can not be found so it definitely is missing in your classpath.

    Tip: you can use winzip to inspect your jars.

    kind regards,

    Jos

    Comment

    • NamelessNumberheadMan
      New Member
      • Jul 2007
      • 15

      #3
      Originally posted by JosAH
      In which .jar file is the class com.microsoft.j dbc.sqlserver.S QLServerDriver stored?
      That's the class that can not be found so it definitely is missing in your classpath.

      Tip: you can use winzip to inspect your jars.

      kind regards,

      Jos
      I did notice one mistake. I was hitting the mssqlserver.jar which is for SQLServer2000. I want to hit sqljdbc.jar which if for SQLServer 2005. So I change my registerDriver to:

      Code:
      DriverManager.registerDriver(new com.microsoft.sqlserver.jdbc.SQLServerDriver());
      I also eliminated the other jars since I ruled those out.

      so my .classpath file now contains:

      [HTML]<?xml version="1.0" encoding="UTF-8"?>
      <classpath>
      <classpathent ry kind="src" path="src"/>
      <classpathent ry kind="con" path="org.eclip se.jdt.launchin g.JRE_CONTAINER "/>
      <classpathent ry exported="true" kind="lib" path="C:/temp/dbInterface/sqljdbc.jar"/>
      <classpathent ry kind="output" path="bin"/>
      </classpath>[/HTML]

      and my MANIFEST.MF contains:

      Manifest-Version: 1.0
      Class-Path: .;C:\temp\dbInt erface\sqljdbc. jar
      Main-Class: com.dbinterface .RunSqlScripts

      I'm still getting this error (and yes SQLServerDriver is in the sqljdbc.jar file). Where can I define my classpath? The command line I guess?
      -classpath .
      -or-
      -classpath C:\temp\dbInter face\sqljdbc.ja r

      These also don't seem to be working. I'm sure it has to be something small that I'm missing. Any ideas?

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by NamelessNumberh eadMan
        Where can I define my classpath? The command line I guess?
        -classpath .
        -or-
        -classpath C:\temp\dbInter face\sqljdbc.ja r

        These also don't seem to be working. I'm sure it has to be something small that I'm missing. Any ideas?
        You could define your classpath like that but what is the purpose of that xml file
        then? It seems as if it defines your classpath in some way but evidently that
        xml file isn't processed or even seen.

        Try to run your class from the command line and pass the correct classpath
        value as you indicated yourself and see what happens.

        kind regards,

        Jos

        Comment

        Working...