Hi guys,
I managed to get the sample web app working on tomcat and mysql. However, mine might not be the best solution and i would appreciate if anyone could add on to what i have posted. First off, there is a known issue with using Hibernate being bound to jndi in tomcat. Refer to 'http://www.hibernate.org/114.html'. And we would have to workaround that which is under 'Creating jbpm.war to be deployed in tomcat' later in this posting.
What i have done to setup the project is
1. Download jbpm-3.0.zip from http://www.jboss.com/products/jbpm/downloads
2. Unzip jbpm-3.0.zip into a 'temp' driectory
3. Using eclipse, import 'temp\jbpm-3.0' as an existing project into workspace
Configuration to connect to MySQL (Assuming you have MySQL server setup and running)
1. Create 'mysql' directory under 'jbpm-3.0\lib'
2. Copy mysql jdbc driver (mysql-connector-java-3.1.7-bin.jar) into 'mysql' directory
3. Login into mysql server and create database <db-name>
4. Under 'jbpm-3.0\src\resources', create 'mysql' directory
5. Copy two configuration files (create.db.hibernate.properties, identity.db.xml) from 'hsqldb' directory into 'mysql' directory
6. Edit the file 'create.db.hibernate.properties' with the following values:
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.url=jdbc:mysql://localhost:3306/<db-name>
hibernate.connection.username=<username>
hibernate.connection.password=<password>
hibernate.show_sql=true
hibernate.query.substitutions=true 1, false 0
hibernate.c3p0.min_size=1
hibernate.c3p0.max_size=3
7. Leave the file 'identity.db.xml' as it is
8. In 'jbpm-3.0' directory, edit the build file 'build.deploy.xml'
In target name="create.db", delete db.start, db.stop if your database server is running by default.
Replace all instance of 'hsqldb' with 'mysql'
9. To populate the database with data, go to directory 'jbpm-3.0' in command prompt and type
ant create.db -buildfile build.deploy.xml
Creating jbpm.war to be deployed in tomcat
The default war file has missing libs as pointed out by one of the user which is true, below are the steps to ensure that all the libs are created with the war file to be deployed in tomcat.
1. In eclipse, edit the build file 'build.deploy.xml'
Go to target name="build.webapp"
Under the task <copy todir="build/jbpm.war.dir/WEB-INF/lib">
Replace existing line
<fileset dir="build" includes="jbpm-webapp-${jbpm.version}.jar" />
with
<fileset dir="build" includes="jbpm*.jar" />
Insert new lines
<fileset dir="lib/hibernate" includes="*.jar" />
<fileset dir="lib/bsh" includes="*.jar" />
2.As Hibernate is unable to bind its SessionFactory to JNDI in tomcat, we will have to modify the way its been created currently. Instead of looking it up using jndi, we will create an instance using the Configuration class within JbpmSessionFactory implementation.
3. Open the source file JbpmSessionFactory.java,
In getInstance() method, delete the lines that does the jndi lookup
InitialContext initialContext = new InitialContext();
Object o = initialContext.lookup(jndiName);
Replace the existing line
instance = (JbpmSessionFactory) PortableRemoteObject.narrow(o, JbpmSessionFactory.class);
with
instance = (JbpmSessionFactory) PortableRemoteObject.narrow(new JbpmSessionFactory(createConfiguration()), JbpmSessionFactory.class);
4.In createConfiguration(String configResource) method,
Comment the block of code
String hibernatePropertiesResource = JbpmConfiguration.getString("jbpm.hibernate.properties");
if (hibernatePropertiesResource!=null) {
Properties hibernateProperties = new Properties();
try {
hibernateProperties.load( ClassLoaderUtil.getStream(hibernatePropertiesResource) );
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("couldn't load the hibernate properties from resource '"hibernatePropertiesResource"'", e);
}
log.debug("overriding hibernate properties with "+ hibernateProperties);
configuration.setProperties(hibernateProperties);
}
and insert
configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
configuration.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
configuration.setProperty("hibernate.connection.url", "jdbc:mysql://localhost:3306/<db-name>");
configuration.setProperty("hibernate.connection.username", "<username>");
configuration.setProperty("hibernate.connection.password", "<password>");
configuration.setProperty("hibernate.connection.pool_size", "15");
5. Go to directory 'jbpm-3.0' in command prompt and type
ant build
ant build.webapp -buildfile build.deploy.xml
6. Copy the generated jbpm.war from 'jbpm-3.0\build' into 'tomcat.home\webapps'
7. Start up tomcat
8. Fire up a web browser and point to 'http://localhost:8080/jbpm'
Hope this posting helps. I know the db connection details has been hard coded instead of reading from a properties file, but i just want to get it working at the first instance, i believed we can easily change the code to look up jndi datasource from tomcat.
Cheers
Jason.
|