0

I want to compile this code with the CMakeList:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

Connection conn = null;
try {
    conn =
    DriverManager.getConnection("jdbc:mysql://localhost/test?" +
                               "user=root&password=wielj12903");


} catch (SQLException ex) {
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());

But when I do this with this CMake-Configuration:

cmake_minimum_required(VERSION 3.5)
project(hello_java LANGUAGES Java)
find_package(Java 1.8 REQUIRED COMPONENTS Development)
file(GLOB_RECURSE SOURCES "src/*.java")
add_jar(name ${SOURCES} ENTRY_POINT Main)

I get the Error that the Connection has no suitable driver

No suitable driver found for jdbc:mysql://localhost/test/user=root&password=wielj12903

But when I compile this Code with the javac-Compiler then everything goes right and it works.

What should i configure in my CMakeList?

Best greetings and thank you for your answer

  • 1
    why do you want to compile javacode with cmake? – tung Apr 04 '18 at 16:59
  • I think you might have a hard time finding people who use CMake to compile java. Most Java developers - in my experience - will use Maven, Gradle or Ant, and those using CMake to compile Java are usually either not familiar with Java or don't use Java as their main programming language. – Mark Rotteveel Apr 05 '18 at 10:15
  • In any case, the error itself is not a compile error, but a runtime error because the driver is not on the classpath at run time. In other words, your question has nothing to do with CMake, but with how you are executing your Java program. – Mark Rotteveel Apr 05 '18 at 10:16

0 Answers0