Sasanka Panguluri
Sasanka Panguluri

Reputation: 3128

Exported Jar file throws exception (JDBC)

I have made use of JDBC in one of my projects and it worked flawlessly in Eclipse. I had to add the ojdbc6.jar to Java Build Path to the project BTW. (I have also not included any Class.forName statements in the code since I heard it's optional for JDBC 4 and above)

When I export the project into a jar file, and try to run it, it complains saying "No driver found for JDBC" and so on. I can see that this is because the ojdbc6.jar is missing from the build path now. Can someone please let me know of a solution?

Thanks!

Upvotes: 0

Views: 631

Answers (3)

Engine Bai
Engine Bai

Reputation: 626

Here is a simple method to export a JAR that uses external jar as libs:

  1. You have to write a manifest file, I named it jar.manifest.
  2. The content in manifest file looks like:

    Manifest-Version:1.0
    Main-Class:com.enginebai.activity.MyJDBCProgram
    Class-Path:lib/ojdbc6.jar lib/some-externam-lib.jar

and make sure to put a blank line under Class-Path, otherwise the JAR won't run. (I have no idea why to put a blank line over there.)

Let's go back to eclipse:

  1. In eclipse, you export your classes and remember to select above manifest file.
  2. Make sure your ojdbc6.jar be in project/lib folder.
  3. Open your terminal and cd to project root directory, enter `java -jar your-jar-name.jar', it should work then.

Upvotes: 1

Sasanka Panguluri
Sasanka Panguluri

Reputation: 3128

I have done some research and found a solution that seems to work. I have exported the project into a "Runnable Jar file" instead of just a "jar file". This way, I was actually able to repack Jar files from my Build Path into the new Jar file I am exporting my project to. Simple and clean.

You also might want to look at signed Jar files and any other certificates in your existing jar files in the Build Path. They cannot directly be repacked through the export option.

Upvotes: 0

Alien11689
Alien11689

Reputation: 471

put ojdbc6.jar on classpath when you run your jar

Upvotes: 0

Related Questions