• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Running a java class with -cp parameter

 
Ranch Hand
Posts: 701
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you need to include the current directory in your classpath? "."
 
Rogerio Kioshi
Ranch Hand
Posts: 701
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Already put "." at classpath variable.

See:
.;%JAVA_HOME%,C:\rogerio\driver_sql\jtds\jtds.jar
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 701
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is your class inside a package?
 
Rogerio Kioshi
Ranch Hand
Posts: 701
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic