• Post Reply Bookmark Topic Watch Topic
  • New Topic

Running a java class with -cp parameter  RSS feed

 
Rogerio Kioshi
Ranch Hand
Posts: 690
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

This question seems to be easy for you.

I created a class with performs a connection to SQL server (ConDBSQL.java).

It is located at
C:\driver_sql\ConDBSQL.java

The driver is located at
C:\driver_sql\jtds\jtds.jar

To compile:
javac ConDBSQL.java (succesful)

To run: java -cp jtds/jtds.jar ConDBSQL
it raises an error: Exception in thread main: java.lang.NoClassDefFoundError:ConDBSQL


I'm using Windows Server 2003. I think my sintax is correct to run ConDBSQL, isn't it?
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you need to include the current directory in your classpath? "."
 
Rogerio Kioshi
Ranch Hand
Posts: 690
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Already put "." at classpath variable.

See:
.;%JAVA_HOME%,C:\rogerio\driver_sql\jtds\jtds.jar
 
Jeff Jetton
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try adding ".." (two periods) to your classpath. That will tell Java to search one directory level up from the current one when it looks for classes.

- Jeff
 
Rogerio Kioshi
Ranch Hand
Posts: 690
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I inserted ".." but still can�t run.

.;..;%JAVA_HOME%,C:\rogerio\driver_sql\jtds\jtds.jar



Also tried to do:
java -cp C:\rogerio\driver_sql\jtds\jtds.jar ConDBSQL (declaring the path explicitly)

But the same error occurs
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is your class inside a package?
 
Rogerio Kioshi
Ranch Hand
Posts: 690
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it's not inside a package.

I solved the problem using Eclipse, creating a MANIFEST File and exporting to a jar file. In the Java build path I specify where my driver is.
The jar file must be in the root directory where I put the driver.


Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!