classpath problem
I am running java on win 95. I have never had to set a classpath variable to compile and run java programs. I have recently installed J2EE in order to have access to the javax.sql package.
Ok, now I have to set the classpath variable so the compiler can find j2ee.jar. After doing so the program (which contains objects from j2ee.jar) compiles without error. However, when I attempt to run this program I get the following error.
"Exception in thread "main" java.lang.NoClassDefFoundError: RStest2/java"
Apparently the java run time cannot find main(). So, I set classpath to null and when I re-run the program I the following error message.
"Exception in thread "main" java.lang.NoClassDefFoundError: sun/jdbc/rowset/Cache
dRowSet
at RStest2.main(RStest2.java:21)"
It now begins to execute main() until line (21)"crs = new CachedRowSet();"then complains. I then changed the classpath variable to also include the path to c:\jdk1.3.1\lib\tools.jar. Running the program again results in the 1st error message ("main" java.lang.NoClassDefFoundError).
Does anyone know why setting the classpath environment variable causes this error?
Thanks!
[1222 byte] By [
BrianB24] at [2007-9-26 1:52:39]

Is the class that contains main() in a package (that is, do you have the line:package somepackagename
at the top of your class)? If so, try removing that. If you do not wish to remove it, then put the following batch file in the same directory as your class containing main (keeping in mind that each package "qualifier" is a directory):
@echo off
:setlocal
set cp=.;<whatever other directories may contain need classes>
:go
cd ..
java -cp %cp% somepackagename.yourclass
cd somepackagename
:end
set cp=
echo Done.
This is how I always test code.
Hope this helps.
AG
No, the class that contains main is not in a package. As a matter of fact all other classes that have been thoroughly tested and run correctly also give the same error
"Exception in thread "main" java.lang.NoClassDefFoundError)"
when I have the classpath variable set. But run perflectly fine when no classpath variable is set.
Here ia a portion of the source.
import java.sql.*;
import javax.sql.*;
import sun.jdbc.rowset.*;
class RStest2
{
public static void main(String args[])
{
Connection c;
Statement s;
ResultSet r;
CachedRowSet crs;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
c = DriverManager.getConnection("jdbc:odbc:pds_dbf","","");
s = c.createStatement();
r = s.executeQuery("SELECT * FROM TEST");
crs = new CachedRowSet();
crs.populate(r);
c.close();
s.close();
showAllForward(crs);
showAllBackward(crs);
}
catch (SQLException SQLe){System.out.println(SQLe.toString());}
catch (ClassNotFoundException CNFe){System.out.println(CNFe.toString());}
}