« Zurück zu Custom Deployments

Derby with Glassfish

Asset-Tag: glassfish derby

Working together with Derby, Glassfish and Liferay.

Glassfish application server includes Derby database. Hence Liferay bundled with Glassfish provides users with an all-in-one ready-made package of database, application server and portal solutions.

Here is the steps:

Derby #

Source #

Suppose that you download liferay-portal-src-5.1.1.zip to your home directory $HOME

unzip liferay-portal-src-5.1.1.zip
cd liferay-portal-src-5.1.1
ant start

Rebuild Derby #

Replace line 64-147 rebuild-derby section of $HOME/liferay-portal-src-5.1.1/sql/build-parent.xml with the following statements.

The modification is for skipping Geronimo deployment and building derby sample database only.

<target name="rebuild-derby">
	<delete dir="${database.name}" failonerror="false" />
	<java
		classname="com.liferay.portal.tools.DBLoader"
		classpathref="project.classpath"
		fork="true"
		maxmemory="256m"
		newenvironment="true"
	>
		<jvmarg value="-Dexternal-properties=com/liferay/portal/tools/dependencies/portal-tools.properties" />
		<jvmarg value="-Dfile.encoding=UTF-8" />
		<arg value="derby" />
		<arg value="${database.name}" />
		<arg value="portal${minimal.suffix}/portal${minimal.suffix}-derby.sql" />
	</java>

	<java
		classname="com.liferay.portal.tools.DBLoader"
		classpathref="project.classpath"
		fork="true"
		maxmemory="256m"
		newenvironment="true"
	>
		<jvmarg value="-Dexternal-properties=com/liferay/portal/tools/dependencies/portal-tools.properties" />
		<jvmarg value="-Dfile.encoding=UTF-8" />
		<arg value="derby" />
		<arg value="${database.name}" />
		<arg value="indexes.sql" />
	</java>

	<tstamp>
		<format property="tstamp.value" pattern="yyyyMMddkkmmssSSS" />
	</tstamp>

	<mkdir dir="${tstamp.value}/geronimo/var/derby/lportal" />

	<move todir="${tstamp.value}/geronimo/var/derby/lportal">
		<fileset dir="${database.name}" />
	</move>

	<jar
		basedir="${tstamp.value}"
		jarfile="${database.name}.jar"
	/>

	<mkdir dir="${database.name}" />

	<move todir="${database.name}">
		<fileset dir="${tstamp.value}/geronimo/var/derby/lportal" />
	</move>

	<delete dir="${tstamp.value}" />
	<if>
		<equals arg1="${app.server.type}" arg2="geronimo-tomcat" />
	<then>
		<tstamp>
		<format property="tstamp.value" pattern="yyyyMMddkkmmssSSS" />
		</tstamp>

		<mkdir dir="${tstamp.value}" />

		<unzip
			src="${app.server.geronimo-tomcat.dir}/repository/org/tranql/tranql-connector-derby-embed-local/1.4/tranql-connector-derby-embed-local-1.4.rar"
			dest="${tstamp.value}"
		/>

		<copy file="${database.name}.jar" todir="${tstamp.value}" />
	
		<delete file="geronimo/derby/tranql-connector-derby-embed-local-1.4.rar" />

		<jar
			basedir="${tstamp.value}"
			jarfile="geronimo/derby/tranql-connector-derby-embed-local-1.4.rar"
		/>

		<delete dir="${tstamp.value}" />
	</then>
	<else>
		<delete file="${database.name}.jar" failonerror="false" />
	</else>
	</if>
</target>

Rebuild Derby database at the directory $HOME/liferay-portal-src-5.1.1/sql/lportal

cd $HOME/liferay-portal-src-5.1.1/sql
ant rebuild-derby

Glassfish #

Download and install Liferay bundled with Glassfish #

Download liferay-portal-glassfish-linux-5.1.1.jar

java -Xmx256m -jar liferay-portal-glassfish-linux-5.1.1.jar -console
cd glassfish
ant -f setup.xml

Setup #

Start Derby #

cd $HOME/liferay-portal-src-5.1.1/glassfish/bin
./asadmin start-database --dbhost 0.0.0.0 --dbport 1527 --dbhome $HOME/liferay-portal-src-5.1.1/sql

The value dbhost is for Derby listen addresses. The default value for the host is 0.0.0.0 which allows all incoming addresses.

The value for the dbhome property represents the location of where the derby databases reside.

Start Glassfish #

./asadmin start-domain domain1

LiferayPool #

  • Use your favorite browser to access http://<your_glassfish_address>:4848
  • Login into admin console, default login is admin, password is adminadmin
  • Goto Resources - JDBC - Connection Pools - LiferayPool
  • Modify and save setting of JDBC connection pool as below:
Datasource Classname	org.apache.derby.jdbc.ClientDataSource
Resource Type		javax.sql.DataSource
connectionAttributes	;create=true
DatabaseName		lportal
User			APP
Password		APP
serverName		localhost
PortNumber		1527

Restart Glassfish#

./asadmin stop-domain domain1
./asadmin start-domain domain1

Done.

Appendix #

Using ij #

ij is an interactive SQL scripting tool provided with Derby, allows you to test and run SQL statements prior to coding JDBC calls.

Assume that you are using Linux, the setup environment is as below:

export DERBY_HOME=$HOME/liferay-portal-src-5.1.1/glassfish/javadb
export DERBY_OPTS=-Dderby.system.home=$HOME/liferay-portal-src-5.1.1/sql
cd $DERBY_HOME/bin
chmod 755 dblook derby_common.sh ij NetworkServerControl setNetworkClientCP setNetworkServerCP startNetworkServer stopNetworkServer sysinfo

Launch ij:

ij
connect 'jdbc:derby://localhost:1527/lportal;create=true;user=APP;password=APP';
disconnect;
exit;

Shutdown procedure #

Shutdown Glassfish first and then stop Derby database.

 ./asadmin stop-database
 ./asadmin stop-domain

Related articles: #

Database Configuration

Liferay with GlassFish

Building and Installing Liferay Source Code on Glassfish v2 and MySQL

1 Anhang
40671 Angesehen
Durchschnitt (0 Stimmen)
Die durchschnittliche Bewertung ist 0.0 von max. 5 Sternen.
Kommentare