maven tomcat7:运行配置数据源

maven tomcat7:运行配置数据源

问题描述:

我有一个多模块Maven项目,我想将其与 tomcat7 maven插件一起使用,并以以下代码开头:

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

mvn tomcat7:run

但是我不知道如何配置jndi数据源.
我尝试放入我的 pom.xml :

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>

并在 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>

但这不起作用...如何注册jndi数据源?

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

错误消息是什么? 使用:

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>

也许您的jdbc驱动程序在类路径中不可用?

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>