运行wiring your web application with...的问题

我用:struts1.1+spring1.2.6+hibernate2.1.8运行wiring your web application with open source java中碰到了如下问题:

  1)、必须遵照作者在源码readme.txt的安装使用说明,尤其是组件版本号,否则就会出问题。

     如:文中要求用 Hibernate 2.1.2,如果用hibernate2.1.8则会出现错误:HibernateException:Unable to locate config file:e:\\pro.xml。(见:HibernateException:Unable to locate config file:e:\\pro.xml (0篇) http://www.learndiary.com/disDiaryContentAction.do?searchDiaryID=1466&goalID=1466&naviStr=a10a2961)因为hibernate2.1.2支持绝对地址文件定位,而2.1.8是把这个文件放在classpath中寻找的,所以把源码中的:“applicationContext-hibernate.xml -

   - <prop key="hibernate.proxool.xml">C:/MyWSADProjects/OnJavaCom/WebContent/WEB-INF/proxool.xml</prop>”

  改为:“applicationContext-hibernate.xml -

   - <prop key="hibernate.proxool.xml">proxool.xml</prop>”

  再把“proxool.xml”放入WEB-INF/classes下面就行了;

  在build.xml文件中要求用:ant1.5.3,我用eclipse2.1下的ant1.5.2出错。

  还有就是源码中没有要求的用:xdolet如果是1.1的版本也不行,用最新的1.2.3解决问题;

  

  2)、把log4j.jar和common-logging.jar(这个文件是否必须这样没有验证)加入系统的classpath,否则会在编译build.xml时说找不到log4j的类。这好像也可以在build.xml文件中指定。

  3)、需要把build.xml中的下列内容改成你机器上的:

“ <property name="xdoclet.lib.home" value="c:/java_api/xdoclet-1.2/lib"/>

<property name="properties.dir"   value="." />

<property name="hibernate.lib.home" value="C:/java_api/hibernate-2.1/lib"/>

<property name="war.webinf.home" value="C:/MyWSADProjects/OnJavaCom/WebContent/WEB-INF"/>

<property name="mysql.lib.home" value="C:/java_api/mysql-connector-java-2.0.14"/>

<property name="db2.lib.home" value="C:/java_api/db2java"/>



   另外,如果你不用db2数据库,就把build.xml中关于db2的东西去掉。否则会出错。

  4)、数据库(mysql)需要先在数据库中把库建起再用build.xml脚本创建表。

  5)、怀疑是作者的笔误,在web.xml文件中的“<param-value>WEB-INF/struts-config.xml</param-value>”应该是“<param-value>WEB-INF/struts-config.xml</param-value>”,否则在我的tomcat5.0下就会报错,但是不知在其它容器中如何?

  6)、还有就是要把每个开源项目的包完整的拷到你的应用程序的lib中,比如:spring就要把它所有的在lib下的第三方支持包全部拷入你的应用程序的lib中。做这些事不要怕有冗余的文件,java的运行机制是要用的时候再去创建类的实例。多些文件只是占点硬盘空间而已。

  我觉得有必要好好的找一找这些错误出现的真正原因。

5 thoughts on “运行wiring your web application with...的问题”

  1. 上面说在这个程序中需要ant1.5.3造成错误,实际上不是这个原因造成的。

    这及上面的试验的环境是:struts1.2+spring1.2.6+hibernate2.1.8

    下面的试验环境是:struts1.1+spring1.0rc2+hibernate2.1.2(及原作者的例程开发环境)

  2. 今天,严格按照作者的各种组件版本来试验,发现eclipse2.1自带的ant1.5.2又不行了,报错为:

    Buildfile: D:\eclipse2.1\workspace\wiring\build.xml

    init:

    hibernate-local:

            [echo] Building Hibernate mappings...

          [delete] Deleting 2 files from D:\eclipse2.1\workspace\wiring\WEB-INF\classes\com\meagle\bo

    [hibernatedoclet] BUILD FAILED: org.apache.commons.logging.LogConfigurationException: java.lang.ClassNotFoundException: org.easystruts.struts.config.EasyStrutsLogFactory

    Total time: 2 seconds

    在eclipse2.1外面用最新的ant1.6.5来编译例程里的ant db-schema-drop又通过了。真是搞不懂。

    在原作者的网站上看到了在tomcat5下运行例程的一个读者的补充,其中就提到了在web.xml中在WEB-INF/struts-config.xml前加“/”的问题。

    原作者的网站上有作者提到的关于proox.xml文件的存放位置在hibernate2.1.6及以后的改动需要。

    java的开源组件间有着错综复杂的关系,一定的程度上又带来了混乱,像上面在我上面日记中的开发环境下ant1.5.2能通过,但是同样上一样的ant,如果其它组件版本变了,它就通不过了。估计上面日记的不知哪个新组件弥补了ant1.5.2的问题,而在这里我严格按照作者的原开发环境后,原来那个弥补ant1.5.2的组件就没有弥补它,所以在ant1.5.2下就通不过了,也许某个开源项目的旧包根据就没有这个弥补ant1.5.2的组件也说不定。

  3.   另外,在把Spring1.0rc2(spring-framework-1.0-rc2)里面dist目录下的文件全部拷入程序的lib中也会说不能加载应用的context,说缺少不个类:java.lang.NoClassDefFoundError:org/aopalliance/intercept/AspectException

    我在Spring目录下的lib\aop-alliance\aopalliance.jar拷入后问题解决。

      但是,在上面日记中用新组件时,不把这个jar文件拷入也正常。

  4. [DEBUG] 09:58 (HouseKeeper.java:sweep:164)

    000007 (00/00/00) - House keeping triggerSweep done

     [DEBUG] 09:58 (Prototyper.java:buildConnection:181)

    000007 (00/01/00) - Connection #109 (324ff) created to achieve minimum of 2 = AVAILABLE -> jdbc:mysql://localhost:3306/wiring (721ee7) by thread Prototyper

     [DEBUG] 09:58 (Prototyper.java:buildConnection:181)

    000007 (00/02/00) - Connection #110 (4adb34) created to achieve minimum of 2 = AVAILABLE -> jdbc:mysql://localhost:3306/wiring (7d4275) by thread Prototyper

     [ INFO] 10:04 (StatisticsLogger.java:statistics:66)

    18:09:00 - 18:10:00, s:0:0.00/s, r:0:0.00/s, a:0.00ms/0.00

     [DEBUG] 10:28 (HouseKeeper.java:sweep:81)

    000007 (00/01/01) - Testing connection 109: False

     [DEBUG] 10:28 (ConnectionPool.java:removeProxyConnection:431)

    000007 (00/01/00) - #0109 removed because it has problems: java.sql.SQLException: Syntax error or access violation,  message from server: "You have an error in your SQL syntax.  Check the manual that corresponds to your MySQL server version for the right syntax to use near 'values(current TimeStamp)' at line 1".

     [DEBUG] 10:28 (HouseKeeper.java:sweep:81)

    000007 (00/00/01) - Testing connection 110: False

     [DEBUG] 10:28 (ConnectionPool.java:removeProxyConnection:431)

    000007 (00/00/00) - #0110 removed because it has problems: java.sql.SQLException: Syntax error or access violation,  message from server: "You have an error in your SQL syntax.  Check the manual that corresponds to your MySQL server version for the right syntax to use near 'values(current TimeStamp)' at line 1".

     [DEBUG] 10:28 (HouseKeeper.java:sweep:164)

    000007 (00/00/00) - House keeping triggerSweep done

  5. 把proxool.xml的下面一句改成mysql中合法的语句:

    <!--<house-keeping-test-sql>values(current TimeStamp)</house-keeping-test-sql>-->

    <house-keeping-test-sql>select CURRENT_DATE</house-keeping-test-sql>

    因为我用的mysql,被注释掉的那句可能在其它数据库中为正确的查询语句,在mysql中就不行了。

      具体还不知道这句的意义,估计是连接测试。

      正常后的debug信息如下:

      

      2006-01-07 20:36:38 [DEBUG] org.logicalcobwebs.proxool.spring (HouseKeeper.java              :164 ) - 000001 (00/02/00) - House keeping triggerSweep done

    2006-01-07 20:37:03 [INFO ] org.logicalcobwebs.proxool.stats.spring (StatisticsLogger.java         :66  ) - 20:36:00 - 20:37:00, s:0:0.00/s, r:0:0.00/s, a:0.00ms/0.00

    2006-01-07 20:37:08 [DEBUG] org.logicalcobwebs.proxool.spring (HouseKeeper.java              :81  ) - 000001 (00/01/01) - Testing connection 1: True

    2006-01-07 20:37:08 [DEBUG] org.logicalcobwebs.proxool.spring (HouseKeeper.java              :81  ) - 000001 (00/01/01) - Testing connection 2: True

    2006-01-07 20:37:08 [DEBUG] org.logicalcobwebs.proxool.spring (HouseKeeper.java              :164 ) - 000001 (00/02/00) - House keeping triggerSweep done

    2006-01-07 20:37:38 [DEBUG] org.logicalcobwebs.proxool.spring (HouseKeeper.java              :81  ) - 000001 (00/01/01) - Testing connection 1: True

    2006-01-07 20:37:38 [DEBUG] org.logicalcobwebs.proxool.spring (HouseKeeper.java              :81  ) - 000001 (00/01/01) - Testing connection 2: True

    2006-01-07 20:37:38 [DEBUG] org.logicalcobwebs.proxool.spring (HouseKeeper.java              :164 ) - 000001 (00/02/00) - House keeping triggerSweep done

    参见proxool0.8.3的文档中配置文件的那部分,摘下来如下:

      Configuration    

      

     

     

    Home

    News

    FAQ

    Tips

    Changes

    The Future

    User Guide

    Licence

    Credits

    User Guide:

    Introduction

    Quick start

    Properties

    Configuration

    Logging

    Admin

    AdminServlet

    Events

    Servlets

    Simple API

    How it works  

    Version 0.8.3

    The latest version of this documentation and software is available on our web site:

    proxool.sf.net 

    last updated: 14-Dec-2003 

      

     You can configure Proxool in lots of ways.

    1. Passing a java.util.Properties object to the Driver when you request a Connection:

    Properties info = new Properties();

    info.setProperty("proxool.maximum-connection-count", "20");

    info.setProperty("proxool.house-keeping-test-sql", "select CURRENT_DATE");

    info.setProperty("user", "sa");

    info.setProperty("password", "");

    String alias = "test";

    String driverClass = "org.hsqldb.jdbcDriver";

    String driverUrl = "jdbc:hsqldb:test";

    String url = "proxool." + alias + ":" + driverClass + ":" + driverUrl;

    connection = DriverManager.getConnection(url, info);

     

    2. Using an XML file. For instance:

    <?xml version="1.0" encoding="ISO-8859-1"?>

    <!-- the proxool configuration can be embedded within your own application's.

    Anything outside the "proxool" tag is ignored. -->

    <something-else-entirely>

      <proxool>

        <alias>xml-test</alias>

        <driver-url>jdbc:hsqldb:.</driver-url>

        <driver-class>org.hsqldb.jdbcDriver</driver-class>

        <driver-properties>

          <property name="user" value="sa"/>

          <property name="password" value=""/>

        </driver-properties>

        <maximum-connection-count>10</maximum-connection-count>

        <house-keeping-test-sql>select CURRENT_DATE</house-keeping-test-sql>

      </proxool>

    </something-else-entirely>

    And then simply call the XML configurator (JAXPConfigurator) in your startup code:

    JAXPConfigurator.configure("src/java-test/org/logicalcobwebs/proxool/configuration/test-no-ns.xml", false);

    // The false means non-validating

    And then, picking up connections is really easy ("xml-test" is the alias we used above)

    connection = DriverManager.getConnection("proxool.xml-test");

    NOTE: you need to include a JAXP compliant XML parser to use this configuration method. For instance, Crimson, or Xerces

    3. Using a properties (flat text) file. For instance

    jdbc-0.proxool.alias=property-test

    jdbc-0.proxool.driver-url=jdbc:hsqldb:.

    jdbc-0.proxool.driver-class=org.hsqldb.jdbcDriver

    jdbc-0.user=sa

    jdbc-0.password=

    jdbc-0.proxool.maximum-connection-count=10

    jdbc-0.proxool.house-keeping-test-sql=select CURRENT_DATE

    The first word (up to the first dot) must start with "jdbc", but it can be anything you like. Use unique names to identify each pool. Any property not starting with "jdbc" will be ignored. The properties prefixed with "proxool." will be used by Proxool while the properties that are not prefixed will be passed on to the delegate JDBC driver.

    And then simply call the property configurator (PropertyConfigurator) in your startup code:

    PropertyConfigurator.configure("src/java-test/org/logicalcobwebs/proxool/configuration/test.properties");

    Again, picking up connections is really easy ("property-test" is the alias we used above)

    connection = DriverManager.getConnection("proxool.property-test");

     

    4. Programmatically. For instance

    Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");

    Properties info = new Properties();

    info.setProperty("proxool.maximum-connection-count", "10");

    info.setProperty("proxool.house-keeping-test-sql", "select CURRENT_DATE");

    info.setProperty("user", "sa");

    info.setProperty("password", "");

    String alias = "test";

    String driverClass = "org.hsqldb.jdbcDriver";

    String driverUrl = "jdbc:hsqldb:test";

    String url = "proxool." + alias + ":" + driverClass + ":" + driverUrl;

    ProxoolFacade.registerConnectionPool(url, info);

    Again, picking up connections is really easy ("test" is the alias we used above)

    connection = DriverManager.getConnection("proxool.test");

     

    5. Using Avalon (choose this if you already use Avalon in your project). For instance:

    role.config -

    <role-list>

      <role

        name="org.logicalcobwebs.proxool.configuration.AvalonConfigurator"

        shorthand="proxool-config"

        default-class="org.logicalcobwebs.proxool.configuration.AvalonConfigurator"/>

    </role-list>

    component.config -

    <component-config>

      <proxool-config>

        <proxool>

          <alias>avalon-test</alias>

          <driver-url>jdbc:hsqldb:.</driver-url>

          <driver-class>org.hsqldb.jdbcDriver</driver-class>

          <driver-properties>

            <property name="user" value="sa"/>

            <property name="password" value=""/>

          </driver-properties>

        </proxool>

      </proxool-config>

    </component-config>

    See AvalonConfigurator.

     

     

Comments are closed.