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"
Related
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
I'm trying to deploy adapters & WLAPP using ANT to a server with a protected Worklight console (form-based).
Here's my ANT task:
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="help">
<taskdef resource="com/worklight/ant/defaults.properties">
<classpath>
<pathelement location="worklight-ant.jar"/>
</classpath>
</taskdef>
<target name="test">
<adapter-deployer deployable="Test.adapter" worklightServerHost="http://testserver/MyApp" userName="username" password="password" />
</target>
</project>
When I run it I got this error message:
adapter-deployer doesn't support the "userName" attribute
The server is running Worklight 6.0
Any ideas?
revised answer: What you're looking to do is not possible in Worklight 6.0.0.0. It was added as part of the Worklight 6.0.0.1 fix pack release via:
PM98052 You cannot deploy with ANT tasks when security is enabled for
the Application Center or Console
Make sure you are using the latest Worklight 6.0.0.x fix pack, currently: Worklight 6.0.0.2 Developer Edition (if you are an IBM customer or business partner, you can get it from Fix Central).
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>
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.
I am executing lot of scp and sshexec and other remote commands from an ant build script. These commands don't work if jsch.jar isn't in the ant lib directory. To make it work, I copied the JAR into the ant lib directory, but this is not a good solution, as anyone else wanting to run the script would have to do the same thing. To run the ant target from Teamcity, we will have to explicitly set the path of the lib file.
Is there a way I can specify the path of the JAR in the ant build XML itself?
Thanks all for your answers. I am managed to get it work with classloader task. This is what I did.
<project basedir="." >
<property environment="env"/>
<taskdef resource="net/jtools/classloadertask/antlib.xml">
<classpath>
<fileset dir="${basedir}/lib" includes="ant-classloader*.jar"/>
</classpath>
</taskdef>
<!--Add JSCH jar to the classpath-->
<classloader loader="system">
<classpath>
<fileset dir="${basedir}/lib" includes="jsch*.jar"/>
</classpath>
</classloader>
<target name="Test">
<scp todir="user1:pass1#server1:/tmp" trust="true" >
<fileset dir="dir1">
<include name="test.txt" />
</fileset>
</scp>
</target>
</project>
As you can see here, I didn't have to give any dependant target for my "Test" target, it just works. It uses classloader, which appends jsch.jar to the system classloader.
One possible work around would be to use the -lib command line option to tell ant where to look for additional jars. Perhaps you could create a wrapper script that calls ant with this option set.
Another way would be to move the ant-jsch.jar file (this is the jar that comes with ant that defines the tasks, not the jsch.jar file you need to download separately) out of your ant lib directory, and create a taskdef for your ssh task separate to the built in one, then set the classpath for this task to the jsch.jar and the ant-jsch.jar:
<taskdef name="sshexec"
classname="org.apache.tools.ant.taskdefs.optional.ssh.SSHExec">
<classpath>
<pathelement location="jsch-0.1.44.jar"/>
<pathelement location="ant-jsch.jar" />
</classpath>
</taskdef>
I'm not sure this will help you though, since it also involves making changes to the lib directory.
As far as I'm aware, it's not currently possible to specify the extra jars required for the built in tasks in the build file itself in general. There are some special cases, like junit for instance.
To ensure your build is more cross platform I'd suggest using dependency management. The ivy plug-in can automatically install the version of your build's plugin at build-time.
This approach means the last jar you'll ever need to install into your ANT lib is ivy-2.2.0.jar :-)
First declare your project's dependencies in the file ivy.xml
<ivy-module version="2.0">
<info organisation="com.myspotontheweb" module="demo"/>
<configurations>
<conf name="anttask" description="Jars implementing ANT tasks"/>
</configurations>
<dependencies>
<dependency org="com.jcraft" name="jsch" rev="0.1.42" conf="anttask->default"/>
</dependencies>
</ivy-module>
Within your build.xml run ivy and use it to populate a custom classpath based on the ivy configuration:
<target name='init' description='Resolve project dependencies and set classpaths'>
<ivy:resolve/>
<ivy:cachepath pathid="anttask.path" conf="anttask"/>
</target>
Finally, elsewhere in your build declare your ANT tasks using the class path now automatically populated by ivy.
<target name='dosomething' depends="init">
<taskdef name="sshexec"
classname="org.apache.tools.ant.taskdefs.optional.ssh.SSHExec"
classpathref="anttask.path"/>
..
..
</target>
This approach works for all ANT plug-ins, most of which are available in the central Maven repository. The second benefit is that it's easy to upgrade the plug-in versions across all builds.