Search code examples
javaspringtomcatderbyspring-jdbc

Why I obtain this exception when I try to deploy and execute on TomCat this application that use Spring?


I am not so into Maven and NetBeans (I used Eclipse and Ant in the past) and I have the following problem trying to deploy and execute on TomCat a web application that use Spring.

I have obtaine a project using the Maven feature named Project from Archetype and choosing the archetype specified from the tutorial (an archetype named entando-archetype-portal-bootstrap, that is an archetype that generate an Entando portal).

In the next NetBeans window I specified the project name as myfirstportal and as Group id I specified com.entando

I have no changed the default project path that is:

/home/andrea/NetBeansProjects/myfirstportal

Then, in the NetBeans projects tab I select my project and I perform the Maven Clean and build task that works for some seconds and that correctly end with a BUILD SUCCESS message.

So it seems that the build process is ok.

Then I select my project and I perform Run, so I choose my TomCat installation.

The starting process start but at the end I always obtain this error message:

ebapp assembled in [9582 msecs]
Building war: /home/andrea/NetBeansProjects/myfirstportal/target/myfirstportal.war

--- tomcat7-maven-plugin:2.1:exec-war-only (war-build-standalone) @ myfirstportal ---
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 31.067s
Finished at: Thu Jul 02 18:23:41 CEST 2015
Final Memory: 48M/233M
------------------------------------------------------------------------
NetBeans: Deploying on Apache Tomcat or TomEE
    profile mode: false
    debug mode: false
    force redeploy: true
Checking data source definitions for missing JDBC drivers...
Undeploying ...
undeploy?path=/myfirstportal
OK - Undeployed application at context path /myfirstportal
In-place deployment at /home/andrea/NetBeansProjects/myfirstportal/target/myfirstportal
Deployment is in progress...
deploy?config=file%3A%2Ftmp%2Fcontext5305066681099450691.xml&path=/myfirstportal
FAIL - Deployed application at context path /myfirstportal but context failed to start

As you can see at the end the process fail with this specific error message:

FAIL - Deployed application at context path /myfirstportal but context failed to start

So I investigated further opening the NetBeans Services window Right-click on the Tomcat Server and select View Server Log and here I obtain the exception that should cause failure:

03-Jul-2015 13:33:40.806 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log No Spring WebApplicationInitializer types detected on classpath
03-Jul-2015 13:33:41.546 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log Initializing Spring root WebApplicationContext
03-Jul-2015 13:33:52.989 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class org.entando.entando.aps.servlet.StartupListener
 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'InitializerManager' defined in class path resource [spring/baseSystemConfig.xml]: Invocation of init method failed; nested exception is java.lang.Exception: Error while initializating Db Installer
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
................................................................
................................................................
................................................................
Caused by: java.lang.Exception: Error while initializating Db Installer
    at org.entando.entando.aps.system.init.InitializerManager.init(InitializerManager.java:49)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
................................................................
................................................................
................................................................
Caused by: java.lang.RuntimeException: Error while loading component installation report - version: production
    at org.entando.entando.aps.system.init.InstallationReportDAO.loadReport(InstallationReportDAO.java:58)
    at org.entando.entando.aps.system.init.AbstractInitializerManager.extractReport(AbstractInitializerManager.java:40)
    ... 66 more
Caused by: com.agiletec.aps.system.exception.ApsSystemException: Error getting connection to the datasource
    at com.agiletec.aps.system.common.AbstractDAO.getConnection(AbstractDAO.java:64)
    at org.entando.entando.aps.system.init.InstallationReportDAO.loadReport(InstallationReportDAO.java:40)
    ... 67 more
Caused by: java.sql.SQLException: Cannot load JDBC driver class 'org.apache.derby.jdbc.EmbeddedDriver'
    at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory(BasicDataSource.java:2043)
    at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:1939)
    at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1412)
    at com.agiletec.aps.system.common.AbstractDAO.getConnection(AbstractDAO.java:61)
    ... 68 more
Caused by: java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1305)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1157)
    at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory(BasicDataSource.java:2034)
    ... 71 more

03-Jul-2015 13:35:54.960 INFO [http-nio-8080-exec-14] org.apache.catalina.core.ApplicationContext.log Closing Spring root WebApplicationContext

It seems that it could depend by some database connectivity problem

What could be the problem? What am I missing? How can I try to fix it?

Tnx

EDIT 1:

So it seems to me that into the Dependencies folder of my NetBeans project (the one that contains all the jar download from Maven) I do'nt have the derby-10.x.x.x.jar file but into the pom.xml file I have this reference to the detby driver class:

<properties>
    <!--
    <test.database.driver>org.postgresql.Driver</test.database.driver>
    <test.database.hostname>localhost</test.database.hostname>
    <test.database.port>5432</test.database.port>
    <test.database.username>agile</test.database.username>
    <test.database.password>agile</test.database.password>
    <test.database.port.url>jdbc:postgresql://${test.database.hostname}:${test.database.port}/${project.artifactId}testPort</test.database.port.url>
    <test.database.serv.url>jdbc:postgresql://${test.database.hostname}:${test.database.port}/${project.artifactId}testServ</test.database.serv.url>
    -->
    <!--
    <test.database.driver>com.mysql.jdbc.Driver</test.database.driver>
    <test.database.hostname>localhost</test.database.hostname>
    <test.database.port>3306</test.database.port>
    <test.database.username>root</test.database.username>
    <test.database.password>agile</test.database.password>
    <test.database.port.url>jdbc:mysql://${test.database.hostname}:${test.database.port}/${project.artifactId}testPort</test.database.port.url>
    <test.database.serv.url>jdbc:mysql://${test.database.hostname}:${test.database.port}/${project.artifactId}testServ</test.database.serv.url>
    -->
    <test.database.driver>org.apache.derby.jdbc.EmbeddedDriver</test.database.driver>
    <test.database.hostname>localhost</test.database.hostname>
    <test.database.port>1527</test.database.port>
    <test.database.username>agile</test.database.username>
    <test.database.password>agile</test.database.password>
    <test.database.port.url>jdbc:derby:${project.build.directory}/test/db/${project.artifactId}testPort;create=true</test.database.port.url>
    <test.database.serv.url>jdbc:derby:${project.build.directory}/test/db/${project.artifactId}testServ;create=true</test.database.serv.url>

    <skipDerby>true</skipDerby>
    <skipStandalone>true</skipStandalone>
    <entando.version>4.2.0-TP1</entando.version>
    <spring.version>4.0.6.RELEASE</spring.version>
    <struts2.version>2.3.16.3</struts2.version>
    <cxf.version>3.0.0-milestone2</cxf.version>
</properties>

As you can see the sections related to postgresql and to MySql DBMS are disablet, instead the one related to org.apache.derby.jdbc.EmbeddedDriver seems to be enabled.

And into the dependencies section I found:

<dependency>
    <groupId>org.apache.derby</groupId>
    <artifactId>derby</artifactId>
    <version>10.9.1.0</version>
</dependency>

<dependency>
    <groupId>org.apache.derby</groupId>
    <artifactId>derbyclient</artifactId>
    <version>10.9.1.0</version>
</dependency>

So I think that Maven should correctly download and configure the derby driver classes.

Why it seems that it have no dowload this jar?


Solution

  • It sais that the Driver was not found. In case of tomcat - put the driver jar into the libs folder and try to start it again.

    EDIT: The way you provide the dependency, it is available only at compile time, but not in the resulting war. I think you should use something like assembly-plugin or shade-plugin in order to provide this jar inside war.

    But if you look at the tomcat documentation... ta-daaa - (search for the word forget) - you should provide the driver jars to the lib folder.