【问题标题】:maven tomcat7:run configure datasourcemaven tomcat7:运行配置数据源
【发布时间】:2014-04-02 20:16:08
【问题描述】:

我有一个多模块 maven 项目,我想将它与 tomcat7 maven 插件 一起使用并使用以下命令开始:

mvn tomcat7:run

但我不知道如何配置 jndi 数据源。
我试图放入我的 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 数据源?

【问题讨论】:

    标签: datasource jndi maven-tomcat-plugin


    【解决方案1】:

    错误信息是什么? 使用:

    <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 驱动程序在类路径中不可用?

    尝试在插件依赖中添加他

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

    【讨论】:

    • 我在应用程序尝试获取它时遇到问题...它抛出一个异常,提示找不到 jdbc/...
    • 你可以试试这样的 contextFile 参数:'${basedir}/tomcat/context.xml'
    猜你喜欢
    • 2015-03-02
    • 2013-07-14
    • 2016-07-12
    • 2017-05-09
    • 2014-07-09
    • 2020-09-21
    • 2015-03-01
    • 2010-12-24
    • 1970-01-01
    相关资源
    最近更新 更多