Skip to content

Instantly share code, notes, and snippets.

@kyle-miho
Last active January 24, 2018 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyle-miho/7a2d169eb24423bd424e890a7243c79e to your computer and use it in GitHub Desktop.
Save kyle-miho/7a2d169eb24423bd424e890a7243c79e to your computer and use it in GitHub Desktop.
Apache Ant Script that can build a working Liferay Bundle from a Liferay Portal given the app.properties are configured correctly.
#For resetting database
sql.prog=C:/Program Files/MySQL/MySQL Server 5.7/bin/mysql.exe
sql.databaseName=lportal
#jar files to be added
sql.jarPath=L:/ImportantFiles
#Liferay portal home
portal.homefolder=L:/private/7.0.x-portal
#Liferay bundle home
bundle.homefolder=L:/apacheTestBundle/liferay-dxp-digital-enterprise-7.0-sp6
#L:/private/liferay-dxp-digital-enterprise-7.0-nightly
#Computer name
computer.name=Kyle-Miho
#servertype
server.type=tomcat
server.foldername=tomcat-8.0.32
#portal-ext.properties properties
portalext.driver=com.mysql.jdbc.Driver
portalext.url=jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
index.on.startup=true
setup.wizard.enabled=false
#Location of ant relative to portal home
antcontrib.location=${portal.homefolder}/lib/development
<?xml version="1.0"?>
<project name="app" default="">
<!--File includes-->
<property file="app.properties"/>
<import file="build.xml"/>
<import file="build-dist.xml"/>
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="${antcontrib.location}/ant-contrib.jar" />
</classpath>
</taskdef>
<!--Plain Portal + pre-reqs -> ant all -> post-reqs -> Ready to execute bundle -->
<target name="all">
<antcall target="pre-ant-all"/>
<ant antfile="build.xml" target="all"/>
<antcall target="post-ant-all"/>
</target>
<!--Tomcat dependencies required before ant all compilation-->
<target name="pre-ant-all">
<antcall target="create-app-server-prop"/>
<antcall target="create-build-prop"/>
<antcall target="unzip-appserver"/>
</target>
<!--Attempts to execute ant -f build-dist.xml unzip-tomcat-->
<target name="unzip-appserver">
<sleep seconds="2"/>
<ant antfile="build-dist.xml" target="unzip-tomcat" />
</target>
<!--Create app-server.Kyle-Miho.properties files-->
<target name="create-app-server-prop">
<echo>Searching for app-server.${computer.name}.properties</echo>
<if>
<available file="app.server.${computer.name}.properties"/>
<then>
<echo>app-server.${computer.name}.properties found! Deleting old version.</echo>
<delete file="app.server.${computer.name}.properties"/>
</then>
<else>
<echo>portal-ext.properties not found! Creating fresh file.</echo>
<touch file="app.server.${computer.name}.properties"/>
</else>
</if>
<echo>Writing to app-server.${computer.name}.properties</echo>
<echo file="app.server.${computer.name}.properties" append="true">
app.server.parent.dir=${bundle.homefolder}
app.server.type=${server.type}
</echo>
<echo>Writing complete!</echo>
</target>
<!--Create build.Kyle-Miho.properties files-->
<target name="create-build-prop">
<echo>Searching for build.${computer.name}.properties</echo>
<if>
<available file="build.${computer.name}.properties"/>
<then>
<echo>app-server.${computer.name}.properties found! Deleting old version.</echo>
<delete file="build.${computer.name}.properties"/>
</then>
<else>
<echo>portal-ext.properties not found! Creating fresh file.</echo>
<touch file="build.${computer.name}.properties"/>
</else>
</if>
<echo>Writing to build.${computer.name}.properties</echo>
<echo file="build.${computer.name}.properties" append="true">
app.server.dir=${bundle.homefolder}/tomcat-8.0.32
javac.compiler=modern
</echo>
<echo>Writing complete!</echo>
</target>
<!--Tomcat dependencies required after ant all compilation-->
<target name="post-ant-all">
<antcall target="reset-db"/>
<antcall target="reset-data-deploy"/>
<antcall target="create-portal-ext-prop"/>
<antcall target="replace-mysql-jar"/>
</target>
<!-- Deletes and creates a fresh MYSQL database -->
<target name="reset-db">
<echo>Resetting Database...</echo>
<exec executable="${sql.prog}">
<arg value="-e"/>
<arg value="drop database if exists ${sql.databaseName}; show databases; create database ${sql.databaseName} char set utf8; show databases;"/>
</exec>
<echo>Resetting successful!</echo>
</target>
<!-- Deletes Data and Deploy Folders -->
<target name="reset-data-deploy">
<echo>Deleting data folder</echo>
<delete dir="${bundle.homefolder}/data"/>
<echo>Deleting home folder</echo>
<delete dir="${bundle.homefolder}/deploy"/>
<echo>Finished deleting folders</echo>
</target>
<!-- Searches for and updates portal-ext.properties-->
<target name="create-portal-ext-prop">
<echo>Searching for portal-ext.properties</echo>
<if>
<available file="${bundle.homefolder}/${server.foldername}/webapps/ROOT/WEB-INF/classes/portal-ext.properties"/>
<then>
<echo>portal-ext.properties found! Deleting old version.</echo>
<delete file="${bundle.homefolder}/${server.foldername}/webapps/ROOT/WEB-INF/classes/portal-ext.properties"/>
</then>
<else>
<echo>portal-ext.properties not found! Creating fresh file.</echo>
<touch file="${bundle.homefolder}/${server.foldername}/webapps/ROOT/WEB-INF/classes/portal-ext.properties"/>
</else>
</if>
<echo>Writing to portal-ext.properties</echo>
<echo file="${bundle.homefolder}/${server.foldername}/webapps/ROOT/WEB-INF/classes/portal-ext.properties" append="true">
# this will turn off an annoying message; you'll want this line
plugins.notification.enabled=false
# these next lines will configure the MySQL connections
jdbc.default.jndi.name=
# dbname is where you specific the name of the database; lportal is the default name
jdbc.default.driverClassName=${portalext.driver}
jdbc.default.url=${portalext.url}
jdbc.default.username=
jdbc.default.password=
# this will set your home directory, which locally stores your data, deploy, and logs folders
browser.launcher.url=
# this will allow Liferay to reindex stuff when starting up
index.on.startup=${index.on.startup}
mail.session.jndi.name=
axis.servlet.hosts.allowed=
tunnel.servlet.hosts.allowed=
setup.wizard.enabled=${setup.wizard.enabled}
</echo>
<echo>Writing complete!</echo>
</target>
<target name="replace-mysql-jar">
<echo>Updating mysql.jar in ${bundle.homefolder}/${server.foldername}/lib/ext</echo>
<copy file="${sql.jarPath}/mysql.jar" todir="${bundle.homefolder}/${server.foldername}/lib/ext"/>
</target>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment