No suitable driver found for jdbc (only in jar file) - jdbc

I'm using netbeans to create a simple java maven application with a very simple JavaDB database connectivity. I've configured the dependencies in maven pom.xml file as follows, and my application works correctly when I run it from the IDE.
pom.xml
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.12.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbyclient</artifactId>
<version>10.12.1.1</version>
</dependency>
Yet when I build the project with dependencies and try to run the final jar, I get the following error.
java.sql.SQLException: No suitable driver found for jdbc:derby://localhost:1527/TestDB
I've even tried copying the derby.jar to the application jar file location. But still the above error appears. I'm not sure what I'm doing wrong.

Related

No suitable driver found for jdbc:firebirdsql://localhost:3050

I build a javafx maven app , using jaybird dependency . Every thing work fine from intelliJ.
when i export the jar file ,I receive this message :
No suitable driver found for jdbc:firebirdsql://localhost:3050...
this is dependencies part of pom.xml:
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>16</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>16</version>
</dependency>
<dependency>
<groupId>org.firebirdsql.jdbc</groupId>
<artifactId>jaybird-jdk16</artifactId>
<version>2.2.14</version>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>5.5.0</version>
</dependency>
</dependencies>
The solution is :
right click on jaybird dependency(follow the image), then click Extract into output root then rebuild the artifact jar.
The normal cause of this error occurring is that either you don't have Jaybird (Firebird JDBC driver) - or one of its required dependencies - on your classpath, or the driver was not registered. Driver registration normally happens automatically, but you can always try to do it explicitly using Class.forName("org.firebirdsql.jdbc.FBDriver"). If this fails, you get a stacktrace that provides further information.
Given you show a Maven pom.xml that includes Jaybird (albeit an older version), the driver is present at compile time. However, depending on how you launch your application, it may not be present on the runtime classpath.
There are several options:
Explicitly specify the driver when loading Java:
java -cp yourapp.jar;jaybird-4.0.3.java8.jar;connector-api-1.5.jar your.class.Name
Here, both jaybird-4.0.3.java8.jar and connector-api-1.5.jar are required for Jaybird to work.
List the required JARs (jaybird-4.0.3.java8.jar and connector-api-1.5.jar) in the Class-Path entry of the manifest of your JAR:
Class-Path: jaybird-4.0.3.java8.jar connector-api-1.5.jar
Both jar files need to be in the same directory as your JAR. You can then launch your application as (assuming the Main-Class attribute is also specified):
java -jar yourapp.jar
Create a fat (or uber) JAR, and make sure all of Jaybird's classes and resources - and those of its required dependencies - are included in your JAR.
(web applications) Include the driver (and dependencies) in the libraries/modules of your application server (e.g. the Tomcat lib folder), or make sure the driver is included in the WEB-INF/lib folder of your WAR (the Maven WAR plugin takes care of this). In this last case (driver in WEB-INF/lib), it is necessary to explicitly load the driver using Class.forName("org.firebirdsql.jdbc.FBDriver") to ensure the driver is registered.

Dependency for driver-class com.ibm.db2.jcc.DB2Driver is missing

i added the followinig dependency for my project to connect to the database:
<dependency>
<groupId>com.ibm.db2.jcc</groupId>
<artifactId>db2jcc4</artifactId>
<version>4.19.26</version>
</dependency>
Since the connection to my database gets refused (ERRORCODE=-4499, SQLSTATE=08001) i tried to add a newer driver
<dependency>
<groupId>com.ibm.db2.jcc</groupId>
<artifactId>db2jcc4</artifactId>
<version>11.1</version>
<scope>system</scope>
<systemPath>${basedir}/lib/com/ibm/db2/jcc/db2jcc4/11.1/db2jcc4-11.1.jar</systemPath>
</dependency>
I installed the jar with the maven install comand in my project directory. It created a lib folder with everything in it.
However i now get the following error:
Dependency for driver-class com.ibm.db2.jcc.DB2Driver is missing!
The maven project is definitly able to locate the jar-file.
There is a second dependency you are missing :
<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>db2jcc_license_cu</artifactId>
<version>11.1</version>
<systemPath>${basedir}/lib/com/ibm/db2/jcc/db2jcc4/11.1/db2jcc_license_cu.jar</systemPath>
</dependency>
Found on nacho4d's blog

Spring Boot - Cleaning up Tomcat dependencies when creating a non-executable war file

From the Spring Boot documentation:
To build a war file that is both executable and deployable into an external container you need to mark the embedded container dependencies as “provided”.
Which looks like this:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
However various tomcat packages still remain as dependencies (and thus show up in my /lib folder), namely:
tomcat-embed-el (a dependency of spring-boot-starter-validation)
tomcat-jdbc (a dependency of spring-boot-starter-jdbc)
Since I will only ever need to deploy my application inside a container and never to run it standalone, how should I proceed with disposing of these dependencies?
P.S. It seems that the first dependency issue is fixed in 1.4.0.M2, see
https://github.com/spring-projects/spring-boot/issues/5454

Is there a maven JBOSS dependency that includes all JBOSS runtime jars?

I have a maven application that will be deployed to JBOSS 5.1 as a war. I want to know how to get it so that Maven can use the JBOSS 5.1 jars (i.e. all the jars in the common/lib folder and any other resources available to JBOSS at runtime) at compile time but not bundle them into the war file.
I thought I could just include some kind of JBOSS dependency with provided scope to do this however I can't find such a dependency. I have done a good bit of searching and can't really find such a dependency. There are a lot of references to pointing to a central JBOSS repository and pulling dependencies from there. I thought there would be just one global dependency that would include all JBOSS runtime jars. Os there such a thing?
If you need more than the standard Java EE API like JBoss packages or resolve some compatibility problems, you can use this dependency :
For JBoss / Java EE 7 Specification APIs
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-7.0</artifactId>
<version>1.0.1.Final</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
For JBoss / Java EE 6 Specification APIs
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>3.0.2.Final</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
For JBoss WildFly 8.2.0.Final complete runtime dependencies
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-parent</artifactId>
<version>8.2.0.Final</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
Now, you can also use those POM files to extract the specific dependencies you need.
This could be useful in remote debug time to let your IDE resolve automatically the server dependencies jars and sources currently loaded, or appearing in stacktraces ... in development mode.
In a production MAVEN build, you probably just need this kind of configuration (depending on your JBoss version) :
http://www.mastertheboss.com/jboss-server/wildfly-8/maven-configuration-for-java-ee-7-projects-on-wildfly
Considering JBoss is an EE container, adding the JavaEE dependency should be enough.
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
Scope provided ensures that JBoss's own libraries are used once the application is deployed to the server.

Cannot resolve Derby 10.5.3.0 dependancies with Maven

I'm trying to build my client application to include Derby 10.5.3.0 in a maven build. My pom.xml dependancy is :
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.5.3.0</version>
<scope>compile</scope>
</dependency>
I get this error during the build:
Could not resolve dependencies for project DERBY:DerbyDemo:jar:0.0.1-SNAPSHOT: Failed to collect dependencies for [org.apache.derby:derby:jar:10.5.3.0 (compile)]
Other versions of Derby build fine. I wanted to use 10.5.3.0 in the build to stay in sync with the version of the server, which is the Oracle Download of Java DB 10.5.3.0
For reference sake, at post time version 10.9.1.0 works:
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.9.1.0</version>
</dependency>
I just picked the latest version from the Derby site
That's a fairly old version of Derby. Not all versions of Derby are stored in the master Maven repositories. Can you use a newer version?

Resources