L’outil Sonar ne se lance pas en localhost avec ma base MySQL

Sonar est un outil open-source qui permet d’obtenir des statistiques avancés sur l’état de votre projet (Java le plus souvent). Il utilise pour cela les rapports générés par les différents plugins de report utilisés par votre projet Maven. Pour plus de précision, vous pouvez aussi lire cet article  sur le contrôle qualité de Sonar.

L’installation est relativement simple, il suffit de télécharger le dernier zip disponible sur le site Sonar et de suivre les instructions d’installation.

L’installation se déroule sans problème avec la base derby utilisée par défaut. Mais impossible de l’installer avec une base MySQL pourtant installé localement? Avez-vous une erreur JNDI?

INFO  org.sonar.INFO  JDBC datasource bound to JNDI, name=jdbc/sonar

Dans le fichier sonar.properties, vous avez certainement dû dé-commenté les lignes suivantes:

sonar.jdbc.url:               jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8
sonar.jdbc.driverClassName:   com.mysql.jdbc.Driver
sonar.jdbc.validationQuery:   select 1

Lorsque que vous connecter à votre serveur http://localhost:9000/

Vous avez le message suivant :


We're sorry, but something went wrong.
Please try back in a few minutes and contact support if the problem persists.
<%= link_to "Go back to the homepage", home_path %>

Dans le fichier de log de sonar : soit sonar.log en mode standalone soit dans catalina.out en mode Tomcat, vous avez une erreur JNDI et vous ne comprenais pas pourquoi?

2011.04.22 13:52:17 INFO  org.sonar.INFO  JDBC datasource bound to JNDI, name=jdbc/sonar
2011.04.22 13:52:17 ERROR o.s.s.p.Platform  Can not start Sonar
org.picocontainer.PicoLifecycleException: PicoLifecycleException: method 'public void org.sonar.server.database.JndiDatabaseConnector.start()', instance 'org.sonar.server.database.JndiDatabaseConnector@940f82, java.lang.RuntimeException: wrapper
	at org.picocontainer.monitors.NullComponentMonitor.lifecycleInvocationFailed(NullComponentMonitor.java:77) [picocontainer-2.10.2.jar:na]
	at org.picocontainer.lifecycle.ReflectionLifecycleStrategy.monitorAndThrowReflectionLifecycleException(ReflectionLifecycleStrategy.java:132) [picocontainer-2.10.2.jar:na]
	at org.picocontainer.lifecycle.ReflectionLifecycleStrategy.invokeMethod(ReflectionLifecycleStrategy.java:115) [picocontainer-2.10.2.jar:na]
	at org.picocontainer.lifecycle.ReflectionLifecycleStrategy.start(ReflectionLifecycleStrategy.java:89) [picocontainer-2.10.2.jar:na]
	at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.start(AbstractInjectionFactory.java:84) [picocontainer-2.10.2.jar:na]
	at org.picocontainer.behaviors.AbstractBehavior.start(AbstractBehavior.java:169) [picocontainer-2.10.2.jar:na]
	at org.picocontainer.behaviors.Stored$RealComponentLifecycle.start(Stored.java:132) [picocontainer-2.10.2.jar:na]
	at org.picocontainer.behaviors.Stored.start(Stored.java:110) [picocontainer-2.10.2.jar:na]
	at org.picocontainer.DefaultPicoContainer.potentiallyStartAdapter(DefaultPicoContainer.java:996) [picocontainer-2.10.2.jar:na]
	at org.picocontainer.DefaultPicoContainer.startAdapters(DefaultPicoContainer.java:989) [picocontainer-2.10.2.jar:na]
	at org.picocontainer.DefaultPicoContainer.start(DefaultPicoContainer.java:746) [picocontainer-2.10.2.jar:na]
	at org.sonar.server.platform.Platform.startDatabaseConnectors(Platform.java:116) [classes/:na]
	at org.sonar.server.platform.Platform.init(Platform.java:88) [classes/:na]
	at org.sonar.server.platform.PlatformLifecycleListener.contextInitialized(PlatformLifecycleListener.java:32) [classes/:na]
	at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:548) [jetty-6.1.24.jar:6.1.24]
	at org.mortbay.jetty.servlet.Context.startContext(Context.java:136) [jetty-6.1.24.jar:6.1.24]
	at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250) [jetty-6.1.24.jar:6.1.24]
	at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517) [jetty-6.1.24.jar:6.1.24]
	at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467) [jetty-6.1.24.jar:6.1.24]
	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50) [jetty-util-6.1.24.jar:6.1.24]
	at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130) [jetty-6.1.24.jar:6.1.24]
	at org.mortbay.jetty.Server.doStart(Server.java:224) [jetty-6.1.24.jar:6.1.24]
	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50) [jetty-util-6.1.24.jar:6.1.24]
	at org.sonar.application.JettyEmbedder.start(JettyEmbedder.java:80) [sonar-application-2.7.jar:na]
	at org.sonar.application.StartServer.main(StartServer.java:48) [sonar-application-2.7.jar:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [na:1.6.0_20]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [na:1.6.0_20]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [na:1.6.0_20]
	at java.lang.reflect.Method.invoke(Method.java:616) [na:1.6.0_20]
	at org.tanukisoftware.wrapper.WrapperSimpleApp.run(WrapperSimpleApp.java:240) [wrapper-3.2.3.jar:3.2.3]
	at java.lang.Thread.run(Thread.java:636) [na:1.6.0_20]
Caused by: java.lang.RuntimeException: wrapper
	at org.picocontainer.lifecycle.ReflectionLifecycleStrategy.monitorAndThrowReflectionLifecycleException(ReflectionLifecycleStrategy.java:130) [picocontainer-2.10.2.jar:na]
	... 29 common frames omitted
Caused by: org.sonar.jpa.session.DatabaseException: Cannot open connection to database: Cannot create PoolableConnectionFactory (Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)
	at org.sonar.jpa.session.AbstractDatabaseConnector.testConnection(AbstractDatabaseConnector.java:186) [sonar-core-2.7.jar:na]
	at org.sonar.jpa.session.AbstractDatabaseConnector.start(AbstractDatabaseConnector.java:98) [sonar-core-2.7.jar:na]
	at org.sonar.server.database.JndiDatabaseConnector.start(JndiDatabaseConnector.java:64) [classes/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [na:1.6.0_20]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [na:1.6.0_20]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [na:1.6.0_20]
	at java.lang.reflect.Method.invoke(Method.java:616) [na:1.6.0_20]
	at org.picocontainer.lifecycle.ReflectionLifecycleStrategy.invokeMethod(ReflectionLifecycleStrategy.java:110) [picocontainer-2.10.2.jar:na]
	... 28 common frames omitted
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)
	at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549) [commons-dbcp-1.3.jar:1.3]
	at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388) [commons-dbcp-1.3.jar:1.3]
	at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044) [commons-dbcp-1.3.jar:1.3]
	at org.sonar.server.database.JndiDatabaseConnector.getConnection(JndiDatabaseConnector.java:153) [classes/:na]
	at org.sonar.jpa.session.AbstractDatabaseConnector.testConnection(AbstractDatabaseConnector.java:182) [sonar-core-2.7.jar:na]
	... 35 common frames omitted
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [na:1.6.0_20]
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) [na:1.6.0_20]
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [na:1.6.0_20]
	at java.lang.reflect.Constructor.newInstance(Constructor.java:532) [na:1.6.0_20]
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:409) [mysql-connector-java-5.1.13.jar:na]
	at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1118) [mysql-connector-java-5.1.13.jar:na]
	at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:343) [mysql-connector-java-5.1.13.jar:na]
	at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2308) [mysql-connector-java-5.1.13.jar:na]
	at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2122) [mysql-connector-java-5.1.13.jar:na]
	at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:774) [mysql-connector-java-5.1.13.jar:na]
	at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:49) [mysql-connector-java-5.1.13.jar:na]
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [na:1.6.0_20]
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) [na:1.6.0_20]
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [na:1.6.0_20]
	at java.lang.reflect.Constructor.newInstance(Constructor.java:532) [na:1.6.0_20]
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:409) [mysql-connector-java-5.1.13.jar:na]
	at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:375) [mysql-connector-java-5.1.13.jar:na]
	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:289) [mysql-connector-java-5.1.13.jar:na]
	at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38) [commons-dbcp-1.3.jar:1.3]
	at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582) [commons-dbcp-1.3.jar:1.3]
	at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556) [commons-dbcp-1.3.jar:1.3]
	at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545) [commons-dbcp-1.3.jar:1.3]
	... 39 common frames omitted
Caused by: java.net.ConnectException: Connection refused
	at java.net.PlainSocketImpl.socketConnect(Native Method) [na:1.6.0_20]
	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:327) [na:1.6.0_20]
	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:193) [na:1.6.0_20]
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180) [na:1.6.0_20]
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:384) [na:1.6.0_20]
	at java.net.Socket.connect(Socket.java:546) [na:1.6.0_20]
	at java.net.Socket.connect(Socket.java:495) [na:1.6.0_20]
	at java.net.Socket.<init>(Socket.java:392) [na:1.6.0_20]
	at java.net.Socket.<init>(Socket.java:235) [na:1.6.0_20]
	at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:256) [mysql-connector-java-5.1.13.jar:na]
	at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:292) [mysql-connector-java-5.1.13.jar:na]
	... 54 common frames omitted

Cette erreur d’interface JNDI n’est vraiment pas très explicite. Pour la corriger, il faut tout simplement remplacer localhost par l’adresse IP de votre serveur.

sonar.jdbc.url:               jdbc:mysql://<MON_ADRESSE_IP>:3306/sonar?useUnicode=true&characterEncoding=utf8
sonar.jdbc.driverClassName:   com.mysql.jdbc.Driver
sonar.jdbc.validationQuery:   select 1

Et là, Sonar va pouvoir installer la base et se lancer. A vos rapports.

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *