I have a program that I wrote a couple years ago for a class, and it worked fine. Recently I updated a lot of things - Java, Eclipse, Tomcat, etc. because I haven't been programming in a while. I messed with the dependencies and now I cannot get it to work. It correctly displays the opening jsp, but never makes it to the handling servlet, giving me a 404 error. I think that I must not have the correct dependency for the servlet anymore? I know the program works, so I have not included code for it. The program uses Eclipselink, mySQL, JSP, and Servlets. (Yes, kicking myself for messing with it). These are the dependencies I have. Am I missing one? Have the wrong one? I am not well versed in maven dependencies
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.39</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.7.6</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa</artifactId>
<version>2.7.6</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.3</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
</dependency>
And my build has:
Apache Tomcat 9
Java jdk 13.1
Maven Dependencies
Thanks for any help you can give.
Well, dang it all. I have been trying to get this working for 2 days. Decided problem was with Tomcat. Downloaded and reinstalled it all. Port errors. Changed to every number in the world. Cleaned server, updated project, etc. Nothing worked. Kept getting port number error. Finally saw where someone said they fixed it by restarting computer. Last ditch effort and for some godforsaken reason, it worked. SOOOOOO frustrating. Thanks for your help anyway. I should know - when in doubt, reboot.
So, while learning Springboot, one of the things that came up was working with DBs and the Springboot Data JPA. After adding the simple dependency (with and without the version):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>1.5.8.RELEASE</version>
</dependency>
and trying to export/build a jar file, with either STS's export or the "mvn clean install"/"mvn clean package" I get the following:
https://pastebin.com/5qDSGejT
This also happens if the project was just created with STS or Spring Initializr and I really have no idea where to start figuring out what's wrong here.
Cannot determine embedded database driver class for database type NONE
The database driver is either missing or corrupt.
Or you simply have not setup a connection to a database.
I would suggest you to double check if your database connection is correct and go into your .m2 folder and delete your maven repositories.
You can easily setup a database connection using application.properties which is located in src/main/resources. Spring boot will take care of the rest.
spring.datasource.url=jdbc:mysql://localhost:3306/DBNAME?useSSL=false
spring.datasource.username = user
spring.datasource.password = pass
It was something with the database at the point of posting the question, but this is not the whole picture. I was getting a different stack trace yesterday. To reach it again, I added a dependency for a DB. Part of the second error was:
Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
It seems the problem lies in Java 9 (which I installed just yesterday) and the new "thing" with modules and Jaxb. So in the end, the solution was in another thread here, about jaxb not being included:
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.7.0</version>
</dependency>
This does fix the problem, but this is such a mess of information, it really is just a band-aid solution.
I'm writing a Java application that makes use of Firebase and the RealtimeDB.
While writing my unit tests, I ran into a rather strange issue in that the Firebase classes can not be loaded inside JUnit, throwing a NoSuchMethodError:
java.lang.NoSuchMethodError: com.google.common.primitives.UnsignedInteger.asUnsigned(I)Lcom/google/common/primitives/UnsignedInteger;
I've managed to track it down to Firebase using a different Guava version than the rest of the project, but even though I've forced the use of Guava 19.0 (through the Maven dependency exclusion mechanism), I'm still getting the same error, apparently when the FirebaseOptions class is being loaded (exact location: com.google.firebase.FirebaseOptions$Builder.setServiceAccount(FirebaseOptions.java:77)).
EDIT:
The problem only appears during a test run, at run-time, the Guava library is loaded correctly.
Does anyone have any ideas on how to provide Firebase with the Guava library properly?
Apparently, the solution was to add the resolution exclusion to the POM (making the final dependency as follows
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-server-sdk</artifactId>
<version>[3.0.0,)</version>
<exclusions>
<exclusion>
<groupId>guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
), then force a purge of the local repository. After re-indexing the project, the test were able to load the appropriate classes without issues.
spring.freemarker.cache:false
spring.datasource.url=jdbc:mysql://localhost/mydb
spring.datasource.username=user
spring.datasource.password=pass
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
im getting this error even with the driver-class-name difined
java.lang.IllegalStateException: Cannot load driver class:
com.mysql.jdbc.Driver at
org.springframework.util.Assert.state(Assert.java:392)
~[spring-core-4.2.1.RELEASE.jar:4.2.1.RELEASE] at
org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.getDriverClassName(DataSourceProperties.java:153)
~[spring-boot-autoconfigure-1.3.0.M5.jar:1.3.0.M5] at
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$NonEmbeddedConfiguration.dataSource(DataSourceAutoConfiguration.java:119)
~[spring-boot-autoconfigure-1.3.0.M5.jar:1.3.0.M5] at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
~[na:1.8.0_60] at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
~[na:1.8.0_60] at ......
and it goes on
If you're using Maven, add this to your pom.xml:
(Recommended) For MySQL 5.6, 5.7, 8.x and Java >= 8 use;
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.30</version>
</dependency>
(Legacy) For MySQL <= 5.5 or Java <= 7 or JDBC < 4.2 use;
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.49</version>
</dependency>
More details on Connector/J versions
It might be that you are using the deprecated driver class name. I solved it by updating the property in application.properties file.
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
Just confirm the following things.
If you are under proxy make sure use VPN to connect to internal servers, iif you are accessing DEV/STG servers
Make sure you add the following dependency inside correct location, like this
<dependencies> <--- inside this section
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.15</version>
</dependency>
</dependencies>
and Not in
`<build> <--- Not this section
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.15</version>
</dependency>
`
3. And you don't need to use the following line
`spring.datasource.driver-class-name=com.mysql.jdbc.Driver.
The spring.datasource.url=jdbc:mysql://xxxxx` automatically know which driver to fetch.
If you are using IDEA and maven, you might forget reloading all maven projects, which causes the dependencies don't have the MySQL connector jar. And that's why when u run the application, there will be the error remind "com.mysql.cj.jdbc.Driver".
The crux of the problem is that you're missing MySQL driver dependency.
One of the ways, as outlined by other answers, is to specify it in your build tool's configuration. However, if you do not want to do it and are using IntelliJ IDEA (though I'm pretty sure Eclipse has something similar), you can also add the dependency via it. Steps:
Download desired jar from maven repository
Open your project in Intellij IDEA
File -> Project Structure -> Libraries
Click New Project Library (green plus sign on the left), or press Alt + Insert keys
Select Java
Select your jar
Press OK
Should look something like this:
Now you should be able to use the dependency you have just added.
Tested with IntelliJ IDEA 2017.3.4.
I will share more causes of this error:
I already seen this error many times using Intellij IDEA and running some integration test. The test fail with the message: Caused by: java.lang.IllegalStateException: Cannot load driver class: org.h2.Driver. After rebuild the project (Build > Rebuild Project) the error disappears.
Another cause of this error is a corrupted JAR. A college was receiving this error (also trying to run integration tests) and, after delete some related jars on .m2 directory, the error was gone.
build.gradle
runtimeOnly 'mysql:mysql-connector-java'
application.yml
spring:
application:
name: apevent
version: 1.0
datasource:
driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/applicaiton
Probably someone still needs an answer (as me before) I solved it by adding the following dependency
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
I encountered the same problem now and solved it after providing the required dependency,
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.15</version>
</dependency>
adding the following dependency solved my issue
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
I know this might be a little late but maybe anyone from the future might find this answer helpful.
This problem arises from potentially three reasons
Incorrect maven or Gradle configuration
Incorrect spring configuration in the application.properties file
Wrong class name on the application.properties file.
To troubleshoot if you are using maven. do not include the version name. This mostly is a recipe for problems, especially in huge applications. use maven autocompletes features to save you a little time.
configure the data source correctly. There are a lot of answers on it to this question. make sure it's correct. sometimes there is a cj that is missing or included where it's not supposed to be. Trial and error might help you discover the problem
if neither of the above options works. Remove spring.datasource.driver-class-name=com.mysql.jdbc.driver completely. I don't know if it magic but this last one worked for me.
GO NERDS!!!
My problem is solved just by refresh the project, perhap the dependency did not load by the time you run the application
I had the same issue. It happened because I forgot to declare the MySQL connector dependency in my pom file. I added the dependency, then boom! The error went away.
For People who uses Gradle 8.0 and beyond. I had to use
implementation 'mysql:mysql-connector-java:8.0.26'
instead of
implementation group: 'mysql', name: 'mysql-connector-java', version: '8.0.26' ,
my application.yml looks like:
spring:
datasource:
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/<Your DB name>?useSSL=false
remember to reload your gradle file
I tried running the Neo4j sample program JavaQuery.java. I used the neo4j maven script provided to get all the dependencies. However when I run it I get the following error:
Exception in thread "main" java.lang.UnsupportedOperationException: No query engine installed.
at org.neo4j.kernel.impl.query.NoQueryEngine.noQueryEngine(NoQueryEngine.java:56)
at org.neo4j.kernel.impl.query.NoQueryEngine.executeQuery(NoQueryEngine.java:33)
at org.neo4j.kernel.InternalAbstractGraphDatabase.execute(InternalAbstractGraphDatabase.java:953)
at org.neo4j.kernel.InternalAbstractGraphDatabase.execute(InternalAbstractGraphDatabase.java:944)
at JavaQuery.JavaQuery.run(JavaQuery.java:60)
at JavaQuery.JavaQuery.main(JavaQuery.java:44)
I haven't found any documentation about how to get the query engine installed.
the simple low level java interface seems to work, but I haven't been able to get Cypher queries to work.
How do I get past this issue?
You need neo4j cypher dependency.
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-cypher</artifactId>
<version>2.2.0</version>
</dependency>
The neo4j-cypher dependency that #shazin mentioned, should come along when you depend on:
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>2.2.0</version>
</dependency>
I had a similar issue and I had the dependency org.neo4j:neo4j:* configured. Here are some ideas.
Cause #1 : Dependency shadowing
It could be one of your dependencies conflicting with transitive dependency from neo4j. Putting neo4j higher in your SBT could solve this issue.
(This was what worked for me)
Cause #2 : Maximum command line reach (Windows only)
Neo4j has tons of jars. It could be the java command that is too long for windows' maximum number of characters. See: How to set a long Java classpath in Windows?