Maven dependency does not update - java

I have a problem with Maven.
I used to use the 6.0.5 mysql-connector but because of some serverTime error I wanted to go back to an older version, but after that I receive:
java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver
Everything stays the same only the dependency has changed:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.5</version>
</dependency>
changes to:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
Maven appears to update the jars properly, only somehow the compiler doesn't see them. Any idea what may cause the problem? When I go back to 6.0.5 version no error appears.

From https://dev.mysql.com/doc/connector-j/6.0/en/connector-j-api-changes.html :
The name of the class that implements java.sql.Driver in MySQL Connector/J has changed from com.mysql.jdbc.Driver to com.mysql.cj.jdbc.Driver. The old class name has been deprecated.
So I presume you updated the Driver classname to the cj package when you upgraded to 6.0.5, but you should change it back to com.mysql.jdbc.Driver make things work with 5.1.38.

Related

WebDriverManager throwing TypeNotPresentException

I am trying to replace my local geckodriver.exe with WebDriverManager, but when i invoke
WebDriverManager.firefoxdriver().setup();
i get the following error
4391 [main] INFO io.github.bonigarcia.wdm.WebDriverManager - Reading https://api.github.com/repos/mozilla/geckodriver/releases to seek geckodriver
4704 [main] WARN io.github.bonigarcia.wdm.WebDriverManager - There was an error managing geckodriver (latest version) (Type com.google.gson.internal.LinkedTreeMap not present) ... trying again using latest driver stored in cache
4704 [main] INFO io.github.bonigarcia.wdm.WebDriverManager - Reading https://api.github.com/repos/mozilla/geckodriver/releases to seek geckodriver
4876 [main] ERROR io.github.bonigarcia.wdm.WebDriverManager - There was an error managing geckodriver (latest version) (Type com.google.gson.internal.LinkedTreeMap not present)
java.lang.TypeNotPresentException: Type com.google.gson.internal.LinkedTreeMap not present
at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:117)
at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:125)
at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
at sun.reflect.generics.visitor.Reifier.reifyTypeArguments(Reifier.java:68)
...
at io.github.bonigarcia.wdm.WebDriverManager.fallback(WebDriverManager.java:825)
at io.github.bonigarcia.wdm.WebDriverManager.handleException(WebDriverManager.java:802)
at io.github.bonigarcia.wdm.WebDriverManager.manage(WebDriverManager.java:599)
at io.github.bonigarcia.wdm.WebDriverManager.setup(WebDriverManager.java:287)
I am using the latest 5.0.3 WebDriverManager from maven
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.0.3</version>
</dependency>
TypeNotPresentException is thrown when an application tries to access a type using a string representing the type's name, but no definition for the type with the specified name can be found.
It's pretty similar to ClassNotFoundException, but not checked during compilation.
But the root cause is:
com.google.gson.internal.LinkedTreeMap not present in the project classpath.
Try to add gson dependency to the project.
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.9.0</version>
</dependency>
https://docs.oracle.com/javase/9/docs/api/java/lang/TypeNotPresentException.html
Change the WebDriverManager scope to test in pom.xml as follows:
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.0.3</version>
<scope>test</scope>
</dependency>
or change the scope to compile in pom.xml as follows:
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.0.3</version>
<scope>compile</scope>
</dependency>
Additionally, you may need to add the slf4j dependency as follows:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
As per Driver Management - Feature:
Although not mandatory, it is highly recommended to use a logger library to trace your application and tests. In the case of WebDriverManager, you will see the relevant steps of the driver management following its traces. See for example the following tutorial to use SLF4J and Logback. Also, you can see an example of a WebDriverManager test using logging here (this example uses this configuration file).
Reference
You can find a couple of relevant detailed discussion in:
I am getting an error while executing the basic website launch using web driver manager

I can't import the JDBC Client Driver from the derby package

I have a Java Derby database running in Netbeans and I'm trying to connect to it using the JDBC driver. However, I cannot import the JDBC driver specifically from the org.apache.derby package.
What I've done:
My pom.xml file contains the following Maven repo's
<!-- https://mvnrepository.com/artifact/org.apache.derby/derby -->
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.15.1.3</version>
<type>jar</type>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.derby/derbyclient -->
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbyclient</artifactId>
<version>10.15.1.3</version>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbynet</artifactId>
<version>10.15.1.3</version>
</dependency>
The Derby db properties says the database is using the driver
as you can see here
When trying to import the JDBC driver, it is seemingly the only thing missing from the derby import list shown in this screenshot
I have also downloaded the derby.jar file and copied it directly into C:\Program Files\Java\jdk8-221\bin
I really can't understand why the JDBC driver specifically is missing.
I see that you are using release 10.15. In this release, the arrangement of the Derby distribution into jar files has changed, and this is probably affecting you.
Please read the 10.15 Release Notes very carefully, and in particular please carefully look at the section "Note for DERBY-6945" for the details of how you have to change your classpath to access the Derby JDBC driver classes.
Probably, all you have to do is to include derbyshared.jar. But please read the entire thing.

Clickhouse JDBC driver class name

Has anyone used Spring JDBC with Clickhouse? What is the driver class name?
spring.datasource.driver-class-name=<what is it?>
I guess it could be it, even though it doesn't look like any other driver class names that I have seen.
spring.datasource.driver-class-name=ru.yandex.clickhouse.ClickHouseDriver
There is also lighter and faster alternative to the official driver version - clickhouse4j. (fork of the official driver with some improvements)
You can use it like this:
spring.datasource.driver-class-name=cc.blynk.clickhouse.ClickHouseDriver
Driver was renamed due to moving vom yandex to clickhouse.com.
Clickhouse Driver
spring.datasource.driver-class-name=com.clickhouse.jdbc.ClickHouseDriver
See https://github.com/ClickHouse/clickhouse-jdbc
Also note Java Client and JDBC Driver MVN dependencies changed as well:
Maven Clickhouse Java Client
<dependency>
<groupId>com.clickhouse</groupId>
<!-- or clickhouse-grpc-client if you prefer gRPC -->
<artifactId>clickhouse-http-client</artifactId>
<version>0.3.2-patch11</version>
</dependency>
Maven Clickhouse JDBC Driver
<dependency>
<!-- please stop using ru.yandex.clickhouse as it's been deprecated -->
<groupId>com.clickhouse</groupId>
<artifactId>clickhouse-jdbc</artifactId>
<version>0.3.2-patch11</version>
<!-- use uber jar with all dependencies included, change classifier to http for smaller jar -->
<classifier>all</classifier>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
Starting 4.0.0 yandex packages will be removed and be non functional!

java.lang.ClassNotFoundException: "com/mysql/jdbc/Driver" with sql driver in pom

EDIT: Fixed the issue - I wasn't declaring the dependency within the apache tomcat plugin:
<extraDependencies>
<extraDependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.1.3.1</version>
</extraDependency>
<extraDependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</extraDependency>
<extraDependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</extraDependency>
</extraDependencies>
As well as being declared in the pom as seen below.
Question:
I'm trying to use the mysql jdbc driver in my maven project:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
But i'm getting:
java.lang.ClassNotFoundException: "com/mysql/jdbc/Driver";
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.ollynural.app.database.retrievedatabase.DatabaseAccessor.returnSummonerDTOFromDatabaseUsingName(DatabaseAccessor.java:53)
EDIT: Tried using the string instead of CLASS, and error is:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
And DatabaseAccessor returnSummonerDTOFromDatabaseUsingName is:
String URL = prop.getProperty("URL");
String USER = prop.getProperty("USER");
String PASS = prop.getProperty("PASS");
String CLASS = prop.getProperty("CLASS");
String TABLE_UNIVERSITY_INFO = prop.getProperty("TABLE_BASIC_INFO");
try {
Class.forName(CLASS);
} catch (ClassNotFoundException e) {
System.out.println("Can't find SQL Driver");
e.printStackTrace();
}
The properties are:
URL="jdbc:mysql://localhost:3306/league_database_schema";
USER="username";
PASS="password"
CLASS="com.mysql.jdbc.Driver";
The properties are getting to the class fine, but I have no idea why it can't find the class. I'm relatively new to maven, and this was working before i moved over to intellij and eclipse, but any help would be incredibly helpful!
Thank you
I would recommend checking the repository to see if the jar file has actually been installed.
Within the repository, you should find it in: (repository name)/mysql/mysql-connector-java/5.1.38/
There should be a jar file mysql-connector-java-5.1.38.jar
and a pom file mysql-connector-java-5.1.38.pom
I believe that should be it for the repository, if anyone has more ideas/corrections please share. Thanks.
I can't tell by the fragment you posted, but is your dependency declared in the dependencies section of your pom, and not in dependencyManagement?

Trouble starting Hibernate Validator due to Bean Validation API

I'm trying to use Hibernate Validator in my project, but it isn't working. On the following line:
SessionFactory sessions = config.buildSessionFactory(builder.build());
I get the following exception:
org.hibernate.cfg.beanvalidation.IntegrationException: Error activating Bean Validation integration
at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.integrate(BeanValidationIntegrator.java:154)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:311)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1857)
at net.myProject.server.util.HibernateUtil.<clinit>(HibernateUtil.java:32)
... 36 more
Caused by: java.lang.NoSuchMethodError: javax.validation.spi.ConfigurationState.getParameterNameProvider()Ljavax/validation/ParameterNameProvider;
at org.hibernate.validator.internal.engine.ValidatorFactoryImpl.<init>(ValidatorFactoryImpl.java:119)
at org.hibernate.validator.HibernateValidator.buildValidatorFactory(HibernateValidator.java:45)
at org.hibernate.validator.internal.engine.ConfigurationImpl.buildValidatorFactory(ConfigurationImpl.java:217)
at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:111)
I found this question which seems quite similar to my problem. He describes his solution as
I had yet another bean validator jar in the class path. But not from
maven, so i didn't realize it. Removing that solved the problem.
I think my problem is the same. On http://hibernate.org/validator/documentation/getting-started/ it says:
This transitively pulls in the dependency to the Bean Validation API
(javax.validation:validation-api:1.1.0.Final)
That must be causing this issue, since reverting to an older version (4.3.1.Final) fixes the issue. Is there a way to force Hibernate to not pull in the Bean Validation API?
Edit: I've tried to exclude the javax-validation api:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.0.3.Final</version>
<exclusions>
<exclusion>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</exclusion>
</exclusions>
</dependency>
But it didn't seem to have any effect.
Try adding this dependency to your pom.xml
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency>
If not consider using hibernate-validator4.2.0.Final I have that one in my config and it is working fine.
For me, the 1.1.0.Final version javax.validation.validation-api had worked. Because, the javax.validation.spi.ConfigurationState interface of 1.1.0.Final has getParameterNameProvider method, which was absent in 1.0.0.GA.
I added the below dependency in pom.xml
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
<scope>test</scope>
</dependency>
I had the problem again. Thats how I've fixed that:
1-Exclude spring.validator from the 'web' dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
</exclusion>
</exclusions>
</dependency>
2-After insert the dependecy with a previous version:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.1.3.Final</version>
</dependency>
in my case i just deleted the hibernate-validator and it worked .(i also had a combo of both validation api and hibernate-validator and tried everything) or you can go to your maven repository-->org and then delete the hibernate folder and rebuild your project again..
hope it helps..
I thought it would be useful to explain what is going on here.
Hibernate is calling ConfigurationState.getParameterNameProvider:
ValidatorFactoryImpl.java:
public ValidatorFactoryImpl(ConfigurationState configurationState) {
...
configurationState.getParameterNameProvider()
...
}
You can find the documentation of getParameterNameProvider:
getParameterNameProvider
ParameterNameProvider getParameterNameProvider()
Returns the parameter name provider for this configuration.
Returns:
parameter name provider instance or null if not defined
Since:
1.1
So what's the problem? The problem is that the method didn't always exist. It was added at some point in the future.
And the rule when creating interfaces is that they are set in concrete: you shall not change an interface ever. Instead the JavaX validator changed the ConfigurationState interface, and added a few new methods over the years.
The java validation code is passing the Hiberate an outdated ConfiguationState interface; one that doesn't implement the required interfaces.
You need to ensure that javax.validation.Validation.buildDefaultValidatorFactory is updated to to support version 1.1.
Removing this jar javax.validation:validation-api:1.1.0.Final solved my problem.
Make sure you have only one validation jar. If we have two jars then they may conflict resulting in error.
Go to the dependecies project and delete, hibernate.validator, and reinstall that in the most recent version. It has solved the problem for me.

Categories