IBM Worklight 6.1 - Ant build failed: Could not load definitions - ant

I've upgraded my worklight server from v6.0 to v6.1.
The target environment is Liberty and Oracle database.
I've build a war for v6.1 and try to deploy it.
it fails with following error message:
[taskdef] Could not load definitions from resource com/worklight/ant/defaults.properties. It could not be found.

The name of ANT jars have changed. So i had to take the new want named "worklight-ant-deployer.jar" instead of "worklight-ant.jar" in my xml config file.
<taskdef resource="com/worklight/ant/defaults.properties">
<classpath>
<fileset dir="${worklight.server.install.dir}/WorklightServer">
<include name="worklight-ant-deployer.jar"/>
</fileset>
</classpath>
</taskdef>

Related

ANT Script to deploy a War file in MobileFirst Server to create run time

I am using Ant script to deploy a war file in mobile first server to create run time. But I am not sure about the ANT Script, I am getting errors regarding database configuration.
This is the error I am getting by running Ant Script:
Building project
command: 'C:\Program Files\agent\opt\apache-ant-1.8.4\bin\ant.bat' -f 'C:\Program Files\agent\var\work\MF-Component\wardeploy.xml'
Buildfile: C:\Program Files\agent\var\work\MF-Component\wardeploy.xml
install:
[configureapplicationserver] Logging output of task <configureApplicationServer> to file C:\Users\miracle\Documents\IBM MobileFirst Platform Server Data\Configuration Logs\configureApplicationServer_2016_02_12_03_35_41.log
[configureapplicationserver] WARNING: The Reports database is deprecated in IBM MobileFirst Platform Foundation since V7.0.0.
[configureapplicationserver] Use Operational Analytics instead.
[configureapplicationserver] See http://ibm.biz/knowctr#SSHS8R_7.1.0/com.ibm.worklight.monitor.doc/monitor/c_op_analytics_overview.html
BUILD FAILED
C:\Program Files\agent\var\work\MF-Component\wardeploy.xml:33: Element <db2> inside <database kind="Worklight"> inside <configureApplicationServer>: Database does not contain the expected tables. The test table GADGET_USER_PREF was not found.
You may create the required tables through an invocation of <configureDatabase>.
Total time: 4 seconds
Caught: com.urbancode.air.ExitCodeException: Command failed with exit code: 1
com.urbancode.air.ExitCodeException: Command failed with exit code: 1
at com.urbancode.air.CommandHelper.runCommand(CommandHelper.groovy:195)
at com.urbancode.air.CommandHelper$runCommand$0.callCurrent(Unknown Source)
at com.urbancode.air.CommandHelper.runCommand(CommandHelper.groovy:121)
at com.urbancode.air.CommandHelper$runCommand.call(Unknown Source)
at ant.run(ant.groovy:123)
Here I don't need any tables to deploy the war file but it was asking for table. For deploying the war file it needs to have database. That I have given the credentials but it shows some errors as above.
Here Is the Ant script I am using.
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="install">
<taskdef resource="com/worklight/ant/deployers/antlib.xml">
<classpath>
<pathelement location="C:\Program Files\IBM\MobileFirst_Platform_Server\WorklightServer\worklight-ant-deployer.jar"/>
</classpath>
</taskdef>
<target name="databases">
<configuredatabase kind="Worklight">
<db2 database="TESTDB" server="172.17.0.177" user="mobusr4" password="mobileuser4">
</db2>
<driverclasspath>
<fileset dir="C:\Program Files\IBM\WebSphere\Liberty\usr\shared\resources\worklight_1\db2">
<include name="db2jcc4.jar"/>
<include name="db2jcc_license_*.jar"/>
</fileset>
</driverclasspath>
</configuredatabase>
<configuredatabase kind="WorklightReports">
<db2 database="TESTDB" server="172.17.0.177" user="mobusr4" password="mobileuser4">
</db2>
<driverclasspath>
<fileset dir="C:\Program Files\IBM\WebSphere\Liberty\usr\shared\resources\worklight_1\db2">
<include name="db2jcc4.jar"/>
<include name="db2jcc_license_*.jar"/>
</fileset>
</driverclasspath>
</configuredatabase>
</target>
<target name="install">
<configureapplicationserver>
<project warfile="C:\Program Files\agent\var\work\MF-Component\bin\Git_Demo.war" libraryfile="C:\Program Files\IBM\MobileFirst_Platform_Server\WorklightServer\worklight-jee-library.jar"/>
<!-- Here you can define values which override the
default values of Worklight configuration properties -->
<property name="serverSessionTimeout" value="10"/>
<applicationserver>
<websphereapplicationserver installdir="C:\Program Files\IBM\WebSphere\Liberty"
profile="Liberty"
user="admin" password="admin">
<server name="UCDServer"/>
</websphereapplicationserver>
</applicationserver>
<database kind="Worklight">
<db2 database="TESTDB" server="172.17.0.177" user="mobusr4" password="mobileuser4"/>
<driverclasspath>
<fileset dir="C:\Program Files\IBM\WebSphere\Liberty\usr\shared\resources\worklight_1\db2">
<include name="db2jcc4.jar"/>
<include name="db2jcc_license_*.jar"/>
</fileset>
</driverclasspath>
</database>
<database kind="WorklightReports">
<db2 database="TESTDB" server="172.17.0.177" user="mobusr4" password="mobileuser4"/>
<driverclasspath>
<fileset dir="C:\Program Files\IBM\WebSphere\Liberty\usr\shared\resources\worklight_1\db2">
<include name="db2jcc4.jar"/>
<include name="db2jcc_license_*.jar"/>
</fileset>
</driverclasspath>
</database>
</configureapplicationserver>
</target>
</project>
This is correct, the WAR file needs to have a database. Before creating the datasource in the application server, the configuredatabase Ant task verifies that the datasource exists and has the correct tables. It didn't find it and failed with an error.
To create the database tables run the 'databases' target in your ant file.
For more information, see https://www-01.ibm.com/support/knowledgecenter/SSHS8R_7.1.0/com.ibm.worklight.deploy.doc/devref/c_project_war_file_ant_tasks.html

Worklight WAR ant configuration to include the Java files

I'm using WL 6.2.0.1 and one of our projects contains a Java files inside the WL server directory.
When I do the build for war file through eclipse I follow the following steps:
1- Right click on the project name > Build Project.
2- Right click on the project name > IBM Mobile Application Platform Pattern > Build Worklight EAR file.
Which generates to me the war file and inside it I see the java files.
When I switched to use ANT script to build the WAR file, I can't see the Java files anymore inside the war file:
ANT script:
<?xml version="1.0" encoding="UTF-8"?>
<project name="MobileApp" default="package" basedir="../">
<property name="WL_PATH" value="./buildscripts"/>
<property name="project.name" value="MobileApp"/>
<taskdef resource="com/worklight/ant/defaults.properties">
<classpath>
<pathelement location="${WL_PATH}/worklight-ant6.2/worklight-ant-builder.jar"/>
</classpath>
</taskdef>
<target name="WAR_CREATE">
<war-builder projectfolder="${basedir}/temp/source/${project.name}"
destinationfolder="bin/war"
warfile="bin/MobileApp.war"
classesFolder="classes-folder"/>
</target>
</project>
I'm not sure if I need to add the Java element to the script so it will compile the Java files. but I tried to add <Javac> but didn't work.
I referred to the following URL : https://ant.apache.org/manual/Tasks/javac.html. But Didn't know which one to use.
Any help thanks.
XML
<?xml version="1.0" encoding="UTF-8"?>
<project name="myProject" default="all">
<taskdef resource="com/worklight/ant/defaults.properties">
<classpath>
<pathelement location="cli_install_dir/public/worklight-ant-builder.jar"/>
</classpath>
</taskdef>
<path id="server-classpath">
<fileset dir="..\jars\Resources" includes="worklight-jee-library.jar" />
<fileset dir="..\jars\Resources\dev" includes="**/*.jar" />
</path>
<mkdir dir="bin\classes"/>
<javac
srcdir="${worklight.repositary}\${proj.brcname}\server\java"
classpathref="server-classpath"
destdir="bin\classes"
verbose="true"
includeantruntime="false"
target="1.6"
/>
<target name="all">
<war-builder projectfolder="."
destinationfolder="bin/war"
warfile="bin/project.war"
classesFolder="bin\classes"/>
</target>
</project>
The Above is the XML is used to Create a War file along with java classes.
Note :
In the places of dir , location and srcdir replace the content directory with your Locations.
Unlike when using the Studio which automatically compiles any Java files that reside under the server\ folder, this does not happen when using the Ant task scripts.
You must first compile these files and point to the folder containing the resulting .class files. This pointing is done in the classesFolder attribute in the Ant task script.
For further elaboration see this answer by me: https://stackoverflow.com/a/30302415/1530814

MobileFirst Building a project WAR file with Ant

I am trying to build the project .war file with Ant in MobileFirst Platform 6.3.
my build.xml has the following:
<?xml version="1.0" encoding="UTF-8"?>
<project name="myProject" default="all">
<taskdef resource="com/worklight/ant/defaults.properties">
<classpath>
<pathelement location="/Applications/IBM/Worklight-CLI/public/worklight-ant-builder.jar"/>
</classpath>
</taskdef>
<target name="all">
<war-builder projectfolder="."
destinationfolder="bin/war"
warfile="bin/project.war"
classesFolder="classes-folder"/>
</target>
</project>
When I execute the Ant script it throws the following error:
[taskdef] Could not load definitions from resource
com/worklight/ant/defaults.properties. It could not be found.
You mention that you are using MFP 6.3, but in your XML you are pointing to "Worklight-CLI", which is not MFP 6.3, but 6.2 or older. Are you sure you're really using MFP 6.3?
It is also referring to the CLI. Are you certain you intend to use the CLI? No where in your question do you mention the CLI...
Verify you have installed the correct version of what you intend to use
Once you've installed the correct version, change the location attribute to:
location="/Applications/IBM/MobileFirst-CLI/mobilefirst-cli/node_modules/generator-worklight-server/ant-tools/worklight-ant-builder.jar"

Deploy worklight application using Ant tasks

I'm using Ant to deploy my application to the production application server(WebSphere).
I use the sample configuration file located in the ${WORKLIGHT_INSTALL_DIR}\configuration-samples folder. the configuration file is marked as suitable for Websphere liberty and Apache derby.
On the configuration sections i change the value (and only this value according with the documentation IBM) of the path element tag (below the code reported).
<taskdef resource="com/worklight/ant/defaults.properties">
<classpath>
<pathelement location="C:\workspace\jQueryMobileApplication\bin\jQueryMobileApplication.war"/>
</classpath>
Setting as location my application war's path. The build.xml file is located in the same folder of my project's war file.
When i type the command :
ant -f <filename>.xml
i get this exception:
Buildfile: C:\IBM\WorklightSRV\WorklightServer\configure-liberty-derby.xml
[taskdef] Could not load definitions from resource com/worklight/ant/defaults.properties. It could not be found.
I'm a newbie with Worklight development(and also with Ant Deployment), so i appreciate any help even if this may be a trivial question.
The classpath is for the worklight-ant.jar to define the tasks to ant
ex.
<taskdef resource="com/worklight/ant/defaults.properties">
<classpath>
<pathelement location="./lib/worklight-ant.jar" />
</classpath>
</taskdef>
After the ant tasks are loaded you can use one of the worklight ant tasks to do your commands
ex.
<echo>Export war file</echo>
<war-builder projectfolder="./<ProjectDirectory>" destinationfolder="bin/war" warfile="bin/Application.war.${env}" classesFolder="<ProjectDirectory>/bin/classes" />
From what i know this will create the war for you but you will have to deploy it manually.

Compiling a build.xml file using Ant

I recently installed Ant 1.8.4 and JasperReports 4.6.0 on my Ubuntu machine.
The following environmental variables were set on my account:
PATH=$PATH:/opt/ant/bin
export PATH
export ANT_HOME=/opt/ant
export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64
When I try to run a demo build file in the JasperReports demo samples directory using the command ant I get the following error:
Buildfile: build.xml
BUILD FAILED
/opt/jasperreports-4.6.0/demo/samples/antcompile/build.xml:3: The following
error occurred while executing this line:
jar:file:/opt/ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml:37: Problem: failed to create task or type componentdef
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
Any help in solving this problem will be super helpful.
The snippet of build.xml file:
<project name="antcompile" default="test" basedir=".">
<description>Shows how multiple JRXML files can be compiled in batch mode using ANT.</description>
<path id="classpath">
<pathelement location="../../../build/classes"/>
<fileset dir="../../../lib">
<include name="**/*.jar"/>
</fileset>
</path>
<path id="runClasspath">
<path refid="classpath"/>
<pathelement location="../../fonts"/>
<pathelement location="./build/classes"/>
</path>
<taskdef name="jrc" classname="net.sf.jasperreports.ant.JRAntCompileTask">
<classpath refid="classpath"/>
</taskdef>
<target name="javac" description="Compiles the Java source files used in the report designs.">
<mkdir dir="./build/classes"/>
<javac srcdir="./src" destdir="./build/classes" debug="true" optimize="false" deprecation="false"/>
</target>
<target name="compile1" description="Compiles report designs specified using the "srcdir" in the <jrc> tag."> <!-- 27 row # -->
<mkdir dir="./build/reports"/>
<jrc
srcdir="./reports"
destdir="./build/reports"
tempdir="./build/reports"
keepjava="true"
xmlvalidation="true">
<classpath refid="runClasspath"/>
<include name="**/*.jrxml"/>
</jrc>
</target>
This Ant script is using custom task jrc.
As you can see from the snippet below (this is build.xml file from the jasperreports-4.6.0/demo/samples/antcompile folder), this task's definition refers the classpath from the same build file.
<path id="classpath">
<pathelement location="../../../build/classes"/>
<fileset dir="../../../lib">
<include name="**/*.jar"/>
</fileset>
</path>
...
<taskdef name="jrc" classname="net.sf.jasperreports.ant.JRAntCompileTask">
<classpath refid="classpath"/>
</taskdef>
You should check the ../../../build/classes folder (in JasperReports package's folder structure which contains samples) - the net.sf.jasperreports.ant.JRAntCompileTask class must be there.
In other words you should put this class (or jasperreports-4.6.0.jar) to the classpath (path id="classpath").
Another probable source of your problem is the version of Ant package.
You can read about Project#createTask complains it wouldn't find task componentdef issue on Ant's bugtracker and project.createTask() not working with ant-1.8.2 post.
I made it work by changing the following element in my CLASSPATH, /opt/jasperreports-4.6.0/lib/ant-1.7.1.jar to /opt/ant/lib/ant.jar.
Thanks to Alex for posting the helpful links!
Anjan
You're going have to help us out a bit here...
Are you building JasperReports-4.6.0? Or, are you using JasperReports as part of your build.xml? Is this a test build.xml demoing JasperReports?
The error says Check that any custom tasks/types have been declared, so what is the Ant task in line #37? Is there a in the build.xml? Does it have a classpath defined? If you have a taskdef, please let us see what it is, and what the custom task is.
I'm downloading iReport to see if I can figure out what you're doing, but it's taking 15 minutes. I bet you're supposed to put some jar into $ANT_HOME/lib. Maybe that JasperReports or iReport jarfile.
As soon as I can download iReport and see what you're talking about, I'll update my answer.
Meanwhile, include the relevant code around line #35 in your build.xml and the taskdef task in your build.xml.
Finished downloading iReport and there is no build.xml file in it. You're going to have to post your code, so we can look at it.
Again, my assumption is that there's some jar file that they assumed you'd stick in /opt/ant/lib and didn't.

Resources