aspose file tools
The moose likes JDBC and the fly likes problems loading the driver within a jar Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "problems loading the driver within a jar" Watch "problems loading the driver within a jar" New topic
Author

problems loading the driver within a jar

Andy Jung
Ranch Hand

Joined: Feb 07, 2010
Posts: 150
Hi all,

Want to load a DB2 Driver within an executable jarfile. The following statements all work if not jared, but don't if they are to be executed within a jar (ClassNotFoundException):




What's the solution to this? Do I need a special ClassLoader for the jar?

Kind regards,
Andy


SCJP, SCJD
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

That's not how Jar files work. You can't package Jars inside Jars. Try shipping the driver with your Jar file not in it.

(NB: if this is the DB2 driver you are probably breaking its licence - from memory I don't think you can distribute it).


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Andy Jung
Ranch Hand

Joined: Feb 07, 2010
Posts: 150
sorry, I didn't express myself correctly.
The jarfile, where the driver is located, is outside my jar of course. However the Java statement, which is to load the driver is inside my jar.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Yes, you'll need a Class-Path instruction in your Jar file.
Andy Jung
Ranch Hand

Joined: Feb 07, 2010
Posts: 150
... isn't it already sufficient to invoke my jar (ts.jar) with -cp option where the classpath is specified?
All the libraries are located under $TAPAS_HOME/lib/ .



Nevertheless, the classpath is also resolved in the manifest-file as follows:





Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Andy Jung wrote:... isn't it already sufficient to invoke my jar (ts.jar) with -cp option where the classpath is specified?
All the libraries are located under $TAPAS_HOME/lib/ .



It is. But if you want the jar to be executable you would use the Class-Path entry (easier for the end user).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problems loading the driver within a jar
 
Similar Threads
Hibernate DB2
Error when getting a connection from DB2 DB
SQL Exception No suitable driver
Doubt on Hibernate application
Could not execute a jar file even with proper classpath.