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 -
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.
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(); } } }
[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.
Comment