0 Replies Latest reply on Aug 5, 2005 12:33 PM by Peter Johnson

    Ant task problem

    Peter Johnson Master

      I am trying to use the Ant tasks that come with the jBPM 3.0 release and I have run into a problem. Here is the build.xml file I am using:

      <?xml version="1.0"?>
      <project name="jbmp-loader" default="loadProcess">
       <property file="build.properties" />
       <path id="classpath">
       <fileset dir="${home.jbpm}/build" includes="**/*.jar" />
       <fileset dir="${home.jbpm}/lib" includes="**/*.jar" />
       <pathelement path="${jar.mysql}" />
       </path>
      
       <target name="loadProcess">
       <taskdef name="jbpm.loadSchema"
       classname="org.jbpm.ant.JbpmSchemaTask"
       classpathref="classpath"
       />
       <jbpm.loadSchema properties="bin/mysql.hibernate.properties"
       actions="load"
       />
       </target>
      </project>


      The build.properties file contains only two lines, one of which identifies where jBPM is installed (I installed the starter?s kit with eclipse, and home.jbpm references the ?jbpm? subdirectory), and the other line references the MySQL jar file.

      When I run, I get the following exception:

      >ant
      Buildfile: build.xml
      
      loadProcess:
       [jbpm.loadSchema] org.hibernate.HibernateException: jbpm.hibernate.cfg.xml not found
      [jbpm.loadSchema] at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1136)
      [jbpm.loadSchema] at org.hibernate.cfg.Configuration.configure(Configuration.java:1160)
      [jbpm.loadSchema] at org.jbpm.db.JbpmSessionFactory.createConfiguration(JbpmSessionFactory.java:111)
      [jbpm.loadSchema] at org.jbpm.db.JbpmSessionFactory.createConfiguration(JbpmSessionFactory.java:102)
      [jbpm.loadSchema] at org.jbpm.ant.AntTaskJbpmSessionFactory.createConfiguration(AntTaskJbpmSessionFactory.java:97)
      [jbpm.loadSchema] at org.jbpm.ant.AntTaskJbpmSessionFactory.getConfiguration(AntTaskJbpmSessionFactory.java:57)
      [jbpm.loadSchema] at org.jbpm.ant.JbpmSchemaTask.execute(JbpmSchemaTask.java:41)
      [jbpm.loadSchema] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
      [jbpm.loadSchema] at org.apache.tools.ant.Task.perform(Task.java:364)
      [jbpm.loadSchema] at org.apache.tools.ant.Target.execute(Target.java:341)
      [jbpm.loadSchema] at org.apache.tools.ant.Target.performTasks(Target.java:369)
      [jbpm.loadSchema] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
      [jbpm.loadSchema] at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
      [jbpm.loadSchema] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
      [jbpm.loadSchema] at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
      [jbpm.loadSchema] at org.apache.tools.ant.Main.runBuild(Main.java:668)
      [jbpm.loadSchema] at org.apache.tools.ant.Main.startAnt(Main.java:187)
      [jbpm.loadSchema] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
      [jbpm.loadSchema] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)
      
      BUILD FAILED
      build.xml:22: couldn't create configuration: jbpm.hibernate.cfg.xml not found


      If I first set my classpath environment variable to include the ${home.jbpm}/build/jbpm.sar.cfg.jar file, the build script runs just fine and the jBPM schema appears in the database.

      My first thought was that Hibernate is not using the correct classloader to search for the jbpm.hibernate.cfg.xml file. The code in org.hibernate.cfg.Configuration is as follows:

      protected InputStream getConfigurationInputStream(String resource) throws HibernateException {
       log.info( "Configuration resource: " + resource );
       InputStream stream = Environment.class.getResourceAsStream( resource );
       if ( stream == null ) stream = Thread.currentThread().getContextClassLoader().getResourceAsStream( resource );
       if ( stream == null ) {
       log.warn( resource + " not found" );
       throw new HibernateException( resource + " not found" );
       }
       return stream;
       }


      This code appears to load the jbpm.hibernate.cfg.xml file using the base classloader (hence why setting a classpath before running Ant works), and when that fails attempting to use the same classloaded for the thread. I added code to also use the same classloader that loaded Configuration, but that didn?t work.

      Any ideas on how to get the JbpmSchemaTask to work in Ant without setting a classpath?