Zeitoun
Zeitoun

Reputation: 173

Error launching tomcat while migrating from java7 tomcat7 to java8 tomcat8

I'm making the switch to Java 8 tomcat 8 on a project that uses tomcat 7 java 7.

I've recompiled the sources without errors.

My problem comes running tomcat.

I can't connect to a resource using this conf :

<GlobalNamingResources>
    <Resource
            name="shared/jdbc/toto"
            auth="Container"
            type="javax.sql.DataSource"
            username="toto"
            password="toto"
            driverClassName="org.postgresql.Driver"
            url="jdbc:postgresql://syt-db:5432/toto"
            maxActive="4"
            maxIdle="2"/>
</GlobalNamingResources>

I get this error :

Cannot load JDBC driver class 'org.postgresql.Driver'
java.lang.ClassNotFoundException: org.postgresql.Driver

I added the factory as seen somewhere on the internet.

<GlobalNamingResources>
    <Resource
            name="shared/jdbc/toto"
            auth="Container"
            factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
            type="javax.sql.DataSourceFactory"
            username="toto"
            password="toto"
            driverClassName="org.postgresql.Driver"
            url="jdbc:postgresql://syt-db:5432/toto"
            maxActive="4"
            maxIdle="2"/>
</GlobalNamingResources>

and got an error like this :

AVERTISSEMENT [localhost-startStop-1] org.apache.naming.NamingContext.lookup Une erreur s est produite durant la résolution de la référence
java.lang.IllegalArgumentException: The local resource link [toto] that refers to global resource [shared/jdbc/toto] does not specify the required attribute type

I feel like now it can use the driver but still has a wrong configuration.

Is my problem really coming from the resource conf or should I focus on something else ?

Thx

Upvotes: 3

Views: 3696

Answers (2)

Zeitoun
Zeitoun

Reputation: 173

I had to add the type="javax.sql.DataSource" in the context of my application

 <ResourceLink
   name="jdbc/toto"
   global="shared/jdbc/toto"
   type="javax.sql.DataSource"
  />

You need to write the type in the ressource definition and in the context of your server.xml

Upvotes: 5

Tobias Otto
Tobias Otto

Reputation: 1676

I think you need to copy the jar-file with the postgres-driver from your old tomcat7 into the new tomcat 8.

Look in the TOMCAT_HOME/lib - directory for the file.

Upvotes: 1

Related Questions