maven tomcat7:run configure datasource

僤鯓⒐⒋嵵緔 提交于 2019-12-10 16:10:40

问题


I have a multimodule maven project, and I want to use it with tomcat7 maven plugin and start it with:

mvn tomcat7:run

But I can't figure out how to configure a jndi datasource.
I've tried to put in my pom.xml:

<plugin>
     <groupId>org.apache.tomcat.maven</groupId>
     <artifactId>tomcat7-maven-plugin</artifactId>
     <version>2.0</version>
     <configuration>
          <contextFile>tomcat/context.xml</contextFile>
     </configuration>
</plugin>

and in the context.xml:

<?xml version="1.0" encoding="UTF-8"?>
<Context>
    <Resource name="jdbc/AppealDS" url="jdbc:hsqldb:file:database/appeal"
         driverClassName="org.hsqldb.jdbcDriver" username="appeal"
         password="appeal" auth="Container" type="javax.sql.DataSource"
         maxActive="3" maxIdle="2" maxWait="10000" />
 </Context>

But it doesn't work...How can I register the jndi datasource?


回答1:


What is the error message? Use:

<plugin>
 <groupId>org.apache.tomcat.maven</groupId>
 <artifactId>tomcat7-maven-plugin</artifactId>
 <version>2.2</version>
 <configuration>
      <contextFile>tomcat/context.xml</contextFile>
 </configuration>
</plugin>

Maybe your jdbc driver is not available in the classpath?

Try adding him in the plugin dependency

<plugin>
 <groupId>org.apache.tomcat.maven</groupId>
 <artifactId>tomcat7-maven-plugin</artifactId>
 <version>2.2</version>
 <configuration>
      <contextFile>tomcat/context.xml</contextFile>
 </configuration>
 <dependencies>
   <dependency>
   here your hsql version
   </dependency>
 </dependencies>
</plugin>


来源:https://stackoverflow.com/questions/22118698/maven-tomcat7run-configure-datasource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!