I developed a Java Application to run on Mac BigSur. I used Java Derby as database for this application. The Application gives an Exception:

java.lang.ClassNotFoundException:org.apache.derby.jdbc.EmbeddedDriver

The interesting fact is that When I run this application on my MacBigSur(Which I have installed on Virtual Box) then the application runs perfectly. But when I run the application on Physical Mac BigSur, then it gives the above mentioned exception.
I am pasting the code Iused for Creating connection to Database.

String dbdriver = "org.apache.derby.jdbc.EmbeddedDriver";
Class.forName(dbdriver).newInstance();
con = DriverManager.getConnection("jdbc:derby:/users/daniyalumar/4DSOFTECHDB; create = true");

Dani AI

Generated

This is a classic classpath/runtime mismatch. As reported, the app runs inside the VirtualBox image but fails on the physical Mac with a driver-not-found error; is correct that the Derby classes are missing from the runtime classpath on the physical machine. Common reasons are different Java installations (the VM may have a JDK that bundled Java DB or an IDE run configuration that adds libraries), running the app differently (IDE vs double-clicked JAR or a launcher that does not include libraries), or placing Derby on the module path instead of the classpath with Java 9+.

Troubleshooting checklist:

  • Compare runtimes on both machines with java -version and which java.
  • Inspect how the app is launched. Running with java -jar ignores an external CLASSPATH, so dependencies must be listed in the manifest or bundled.
  • Confirm the Derby runtime JAR is present in the deployed package (derby.jar contains the embedded driver) and that the jar actually contains the driver class by listing its contents.
  • If using JDK 9+, prefer putting Derby on the classpath (unnamed module) or add proper module exports; otherwise automatic loading can fail.
  • Fix options: add Derby as an explicit dependency and build an uber/fat JAR (maven-shade or Gradle Shadow), include the JARs in a lib folder with a launcher script, or add the jars to the application manifest Class-Path.

Official resources: Apache Derby and org.apache.derby:derby on Maven Central.

The error message you are getting, java.lang.ClassNotFoundException:org.apache.derby.jdbc.EmbeddedDriver, indicates that the EmbeddedDriver class could not be found. This suggests that the necessary classes for the Apache Derby database may not be on the classpath when the application is run on the physical Mac BigSur.

To fix this issue, you will need to make sure that the Apache Derby classes are on the classpath when running the application. There are a few ways you can do this.

One way is to include the Apache Derby JAR file on the classpath when running the application. For example, you can use the -cp or -classpath option when running the java command to specify the path to the Apache Derby JAR file:

java -cp /path/to/derby.jar MyApplication

Another way is to add the Apache Derby JAR file to the lib directory of the Java installation on your physical Mac BigSur. This will make the Apache Derby classes available on the classpath for all Java applications run on the system.

If you are using a build tool like Maven or Gradle, you can also include the Apache Derby dependency in your project and specify the version of the Apache Derby JAR to use. The build tool will then handle downloading and adding the necessary JAR files to the classpath when building and running the application.

I hope this helps! Let me know if you have any other questions.

commented: I have already added the Derby.jar files in lib folder of my Java Application , despite of this I am facing this issue +3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.