Bernhard Hagmann
Bernhard Hagmann

Reputation: 71

Sonar, Maven, Jenkins, MySQL - Cannot create JDBC driver of class 'com.mysql.jdbc.Driver'

Situation


We're running sonar with a MySQL database, jenkins and a build environment with maven.

Problem


When executing a jenkins job it is aborted with the message:

[ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.0:sonar (default-cli) on project playground_eb: Can not execute Sonar: Fail to connect to database: Cannot create JDBC driver of class 'com.mysql.jdbc.Driver' for connect URL 'http://192.168.1.220:3306': No suitable driver

Configuration


Servers


192.168.1.220 (Debian 6.0.6):
  - runs Jenkins (@ port 8080)
  - Sonar (@ port 9000)
  - MySQL Database (@ port 3306)
192.168.1.221 (Windows 7):
  - runs Maven and the whole build environment

Configurations

The database was configured in the sonar.properties file - with localhost. Sonar and its database were configured via the jenkins web interface - with the IP. I guess this could cause errors but configuring the IP in the sonar.properties file causes sonar to not even start up anymore.

Full exception stack



    org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.0:sonar (default-cli) on project playground_eb: Can not execute Sonar
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
    Caused by: org.apache.maven.plugin.MojoExecutionException: Can not execute Sonar
        at org.codehaus.mojo.sonar.Bootstraper.executeMojo(Bootstraper.java:118)
        at org.codehaus.mojo.sonar.Bootstraper.start(Bootstraper.java:65)
        at org.codehaus.mojo.sonar.SonarMojo.execute(SonarMojo.java:90)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
        ... 19 more
    Caused by: java.lang.IllegalStateException: Fail to connect to database
        at org.sonar.core.persistence.DefaultDatabase.start(DefaultDatabase.java:74)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.picocontainer.lifecycle.ReflectionLifecycleStrategy.invokeMethod(ReflectionLifecycleStrategy.java:110)
        at org.picocontainer.lifecycle.ReflectionLifecycleStrategy.start(ReflectionLifecycleStrategy.java:89)
        at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.start(AbstractInjectionFactory.java:84)
        at org.picocontainer.behaviors.AbstractBehavior.start(AbstractBehavior.java:169)
        at org.picocontainer.behaviors.Stored$RealComponentLifecycle.start(Stored.java:132)
        at org.picocontainer.behaviors.Stored.start(Stored.java:110)
        at org.picocontainer.DefaultPicoContainer.potentiallyStartAdapter(DefaultPicoContainer.java:1009)
        at org.picocontainer.DefaultPicoContainer.startAdapters(DefaultPicoContainer.java:1002)
        at org.picocontainer.DefaultPicoContainer.start(DefaultPicoContainer.java:760)
        at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:72)
        at org.sonar.batch.bootstrap.Module.start(Module.java:67)
        at org.sonar.batch.bootstrap.BootstrapModule.doStart(BootstrapModule.java:83)
        at org.sonar.batch.bootstrap.Module.start(Module.java:68)
        at org.sonar.batch.bootstrapper.Batch.startBatch(Batch.java:75)
        at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:60)
        at org.sonar.maven3.SonarMojo.execute(SonarMojo.java:142)
        at org.codehaus.mojo.sonar.Bootstraper.executeMojo(Bootstraper.java:113)
        ... 23 more
    Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class 'com.mysql.jdbc.Driver' for connect URL 'http://192.168.1.220:3306'
        at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1452)
        at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
        at org.apache.commons.dbcp.BasicDataSource.getLogWriter(BasicDataSource.java:1098)
        at org.apache.commons.dbcp.BasicDataSourceFactory.createDataSource(BasicDataSourceFactory.java:350)
        at org.sonar.core.persistence.DefaultDatabase.initDatasource(DefaultDatabase.java:131)
        at org.sonar.core.persistence.DefaultDatabase.start(DefaultDatabase.java:68)
        ... 44 more
    Caused by: java.sql.SQLException: No suitable driver
        at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1443)
        ... 49 more

Upvotes: 2

Views: 6333

Answers (1)

Bernhard Hagmann
Bernhard Hagmann

Reputation: 71

Just found the problem.

In Jenkins the Sonar database URL was set to

http://192.168.1.221:3306/sonar

Now I set it to the WHOLE JDBC-URL (including jdbc: ...) just like in the sonar.properties file ... and now it works.

Upvotes: 4

Related Questions