1

The library I am planing to use is a jdbc driver for a MySQL, it is in a jar file format.

mysql-connector-java-8.0.16.jar

To use this jar file I added an extra line to the module-info file.

requires mysql.connector.java;

After doing this, I created the following directory structure

C:.
├───javaprojects
    │    mysql-connector-java-8.0.16.jar
    │
    └───Hour
        │   module-info.java
        │
        └───com
            └───java24hours
                 |
                 Example.java

However, when compiling Example.java I get the following compile errors

module not found: mysql.connector.java

error: cannot access module-info
cannot resolve modules

So what could be the problem? (BTW I am using notepad to create my java files)

Jeff Mergler
  • 1,384
  • 20
  • 27
zceemdu
  • 11
  • 4
  • Is the `mysql-connector-java-8.0.16.jar` on the classpath when you compile your code? – Karol Dowbecki Jul 18 '19 at 20:21
  • I have not used the classpath – zceemdu Jul 18 '19 at 20:30
  • You should go back and read [docs on classpath](https://docs.oracle.com/javase/tutorial/essential/environment/paths.html) before diving into Java modules. – Karol Dowbecki Jul 18 '19 at 20:55
  • Because java is now modular, I am trying to place it on the modulepath but I have no idea how it is done because up until now I haven't dealt with external libraries. – zceemdu Jul 18 '19 at 23:23
  • See [this](https://stackoverflow.com/a/46715853/6367213) to double check the name of the automatic module you are using. Furthermore, please edit your question with the full `javac` command string you have used when trying to compile your project. – Janez Kuhar Jan 02 '20 at 02:29

2 Answers2

0

Java 9 can handle modules, or plain jars. For the former use the module-path for the latter use the class-path.

mysql-connector.java library is a plain jar and as such must be included in the class-path.

Germán Bouzas
  • 1,430
  • 1
  • 13
  • 18
  • The mysql connector can be used from the module path as an [automatic module](https://stackoverflow.com/questions/46741907/what-is-an-automatic-module), [like this](https://stackoverflow.com/a/71063997/1155209). In the future it may be possible to use it as a standard module, if the developers of the connector update it to include module-info. – jewelsea Jun 15 '22 at 23:28
0

We are supposed to add my-sql-driver under the module path and add requires driver name in module-info.java

enter image description here

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103