Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » No suitable driver found for 'ojdbc6.jar'(java -jar file.jar fails with error with CLASSPATH set)
No suitable driver found for 'ojdbc6.jar' [message #1016054] Mon, 04 March 2013 13:23 Go to next message
Richard Francis is currently offline Richard Francis
Messages: 4
Registered: March 2013
Junior Member
Hi, this may appear simple and i hope it is...thanks for helping.

Using Eclipse SDK 4.2.1 on Windows Server 2003 SP2, Java jdk1.6.0_24

I build jar with referencd lib of ojdbc6.jar, right click select export -> java, jarfile -> next -> keep all defaults on jar file specs -> next -> keep defaults on jar packaging options -> next -> on jar manifest specs I have to select (and this is another question - why do i have to do this - or is this required, if required, why is it required, if I don't select this the jar fails with Failed to load Main-Class manifest attribute from file.jar) the class of the application entry point -> next -> finish

Then I copy the jar file into a directory where I've copied the ojdbc6.jar file. Then I set CLASSPATH=c:\file\ojdbc6.jar;c:\file\file.jar;.;

When I run the jar with 'java -jar file.jar' it fails with the error:
No suitable driver found for jdbc:oracle:thin:@10.10.10.10:1521:orcl
Retrying Connection for 1 time


However, when I build the jar manually, it works fine.
0. md c:\file\com\tasks
1. copy file.java to c:\file, copy ojdbc6.jar to c:\file, copy file.class to c:\file\com\tasks
2. javac file.java
3. jar -cvf file.jar com*
4. run with java com.tasks.file

java code executes without errors...what gives with the Eclipse setup, why doesn't java -jar file.jar work and why do i have set the application entry point.
Re: No suitable driver found for 'ojdbc6.jar' [message #1016601 is a reply to message #1016054] Thu, 07 March 2013 01:10 Go to previous messageGo to next message
David Wegener is currently offline David Wegener
Messages: 1336
Registered: July 2009
Senior Member
java -jar doesn't use the Classpath environment variable to set the classpath. It expects the classpath to be included in the manifest file.

You have to set the entry point so that the Java VM knows what to call when starting the application. There can be any number of public static main methods in a jar file.
Re: No suitable driver found for 'ojdbc6.jar' [message #1016794 is a reply to message #1016054] Thu, 07 March 2013 12:29 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan Herrmann
Messages: 994
Registered: July 2009
Senior Member
Richard Francis wrote on Mon, 04 March 2013 19:23

4. run with java com.tasks.file


If that's really how you invoke the program in the good case, you're comparing apples and oranges.

Try to really compare the same configuration and also check if anything could be loaded "accidentally" because, e.g., "." is on the classpath.
Re: No suitable driver found for 'ojdbc6.jar' [message #1016821 is a reply to message #1016601] Thu, 07 March 2013 14:46 Go to previous messageGo to next message
Richard Francis is currently offline Richard Francis
Messages: 4
Registered: March 2013
Junior Member
Makes sense...then how is classpath set in the MANIFEST.MF...all I'm able to see is the Main-Class entry....without manually editing if possible.

When I export, I'm including .classpath...and I've also included ojdbc6.jar as a referenced library. Though still getting:

=================== STACK TRACE STARTS ====================
File :: getOracleConnectionWithTimeout() :: oracle.jdbc.OracleDriverjava.lang.ClassNotFoundException: oracle.jdbc.OracleDriver
=================== STACK TRACE ENDS ===================

===========================================================
No suitable driver found for jdbc:oracle:thin:@10.10.10.10:1521:orcl
Retrying Connection for 1 time
No suitable driver found for jdbc:oracle:thin:@10.10.10.10:1521:orcl
Retrying Connection for 2 time
Time Slice has Expired
Re: No suitable driver found for 'ojdbc6.jar' [message #1016848 is a reply to message #1016821] Thu, 07 March 2013 16:35 Go to previous messageGo to next message
David Wegener is currently offline David Wegener
Messages: 1336
Registered: July 2009
Senior Member
Please look at the Oracle tutorial for jar files.

http://docs.oracle.com/javase/tutorial/deployment/jar/
Re: No suitable driver found for 'ojdbc6.jar' [message #1016854 is a reply to message #1016848] Thu, 07 March 2013 17:17 Go to previous messageGo to next message
Richard Francis is currently offline Richard Francis
Messages: 4
Registered: March 2013
Junior Member
Hi, thanks.

It appears that Eclipse is unable to automatically add the classpath...so one HAS to use either the jar cfm command or create then edit MANIFEST.MF then export and point to it.

So why doesn't Eclipse do this for the user, automatically by pulling in the libraries and refernced libraries.
Re: No suitable driver found for 'ojdbc6.jar' [message #1016857 is a reply to message #1016854] Thu, 07 March 2013 17:42 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan Herrmann
Messages: 994
Registered: July 2009
Senior Member
JDT has some help pages. How about this one:
http://help.eclipse.org/topic/org.eclipse.jdt.doc.user/reference/ref-export-runnable-jar.htm&anchor=library-handling
icon7.gif  Re: No suitable driver found for 'ojdbc6.jar' [message #1017067 is a reply to message #1016857] Fri, 08 March 2013 14:58 Go to previous message
Richard Francis is currently offline Richard Francis
Messages: 4
Registered: March 2013
Junior Member
Razz Thanks very much everyone.

After saving the MANIFEST.MF, then editing and adding the Main Class entries, on re-export, and running java -jar file.jar, it worked as expected.

My recommendation is to have the build manifest action put the name of the jar and any referenced jars on the Main Class line of the manifest file automatically. If that's objectionable for some reason...why?
Previous Topic:ECJ Java 7 access private of generic
Next Topic:Query about iDocIt! plug-in
Goto Forum:
  


Current Time: Wed Aug 20 08:41:33 EDT 2014

Powered by FUDForum. Page generated in 0.02284 seconds