How to run Apache ant in offline mode? - ant

In the project's build.xml there is this line:
<target name="resolve" depends="init-x" unless="offline">
But how to enable the offline mode?
Neither the online documentation nor ant's manpage mentions the "offline" mode.

The documentation doesn't mention an offline mode because there is no offline mode in Ant. Whoever wrote your build file made it sensitive to the existence of a property named offline.
Your build file contains a target that uses the unless attribute. This means the target will not be executed if an Ant property with the name offline exists.
When running Ant from the command line you can set it via -Doffline=foo. Note the value of the property doesn't matter for Ant's unless attribute, so -Doffline=false will still mean your target will be skipped.

Related

updateapplicationserver ant task always fail with "WAR file is not currently deployed"

I used a very basic build file taken from the sample configure-was-derby.xml:
<property name="worklight.server.install.dir" value="C:/Worklight70"/>
<property name="config.migration.tool.enable" value="true"/>
<target name="minimal-update">
<updateapplicationserver id="" contextroot="/AreaClienti">
<project warfile="C:/temp/AreaClienti.war"/>
<applicationserver>
<websphereapplicationserver installdir="C:/WebSphere85/AppServer"/" profile="AppSrv01" user="wasuser" password="xxxxx">
<server name="server1"/>
</websphereapplicationserver>
</applicationserver>
</updateapplicationserver>
</target>
Recently I was able to reproduce the issue on my laptop installation and I believe I found the cause: please review the following analysis and confirm the results.
I originally installed the war file manually from WAS admin console, and when I run the Ant minimal-update with the above build file it failed with the mentioned error
The MobileFirst Project WAR file is not currently deployed in the WAS
profile at ...
Then I removed the manually installed war file and reinstalled it using Ant install target.
At this point the minimal-update run successfully.
I found out that the Ant installation created into WAS config structure
profile_root/config/cells/cell_name/nodes/node_name/servers/server1
a new Worklight directory containing the worklight-jee-library.jar file and a derby subdir with the derby driver jar.
Apparently the minimal-update Ant task makes a preliminary check on the existence of the Worklight directory and it fails if it's missing.
Can you please confirm that this is true ?
Of course the Worklight directory is not created by the standard WAS installation process.
So, after a console installation of the runtime war the Ant minimal-update always fails!
If I manually add the Worklight dir in WAS config, then the Ant minimal-update starts running just fine.
IMHO, altering in such way the standard WAS config structure is not very clean.
Said that, is it a valid workaround in case we initially install the runtime war with standard WAS admin procedures ?
Furthemore, also the returned error message could have been a bit more clear: please let me know if there is any debug option to make the Ant tasks more verbose.
At last, let me ask one further question.
I noticed that the Ant execution writes log files in the directory
user_root/.mobilefirst_platform_server
Is there any way to redirect those logs into a different dir to avoid the risk of filling up the user root ?
Apparently the minimal-update Ant task makes a preliminary check on the existence of the Worklight directory and it fails if it's missing. Can you please confirm that this is true ?
That's correct.
Is there any way to redirect those logs into a different dir to avoid the risk of filling up the user root ?
Unfortunately not.

Is there a way to expand an ant property inside a target description?

Is it possible to have ant help use values of properties inside a target description? Just using the ${} notation doesn't seem to work
build file:
<property name="test.report.dir" value="report"/>
...
<target name="test" depends="compile.main, compile.test" description="Runs unit tests. Reports are saved in ${test.report.dir}/">
...
terminal:
ant -p
Buildfile: /home/aaron/Projects/DataStore/build.xml
Main targets:
...
test Runs unit tests. Reports are saved in ${test.report.dir}/
...
This was suggested as a solution in Echo target description in Ant, but as a commenter noted, it doesn't expand the property.
I'm using ant 1.9.3 on Ubuntu.
No it is not possible. A target description is read as it is: no property evaluation is done. It makes sense because:
A target description is expected to provided a general information about the behavior of the target, which is irrelevant to the value of a certain property.
The project help -p option does not execute the Ant tasks contained in a buildfile, so it cannot evaluate properties defined using the property task.

Retrieval of Jenkins environment variables while invoking ANT

I am invoking a windows batch command from Jenkins, after i get the latest version of my project from SVN. the windows batch command just performs certain file copying, after the all the files are retrieved from SVN and runs an ANT build. In the ANT build process, i am generating a JSP file where i have tried to capture the in the following fashion.
%BUILD_TAG%-%BUILD_NUMBER%-%BUILD_ID%-%SVN_REVISION%
Unfortunately none of this information is understood by the build process and it just writes %BUILD_TAG%-%BUILD_NUMBER%-%BUILD_ID%-%SVN_REVISION% into the file.
Could you please let me know if there is a way to capture these information into a file in the way i am trying to do? if not, could you direct me on how these information could be captured into a JSP file during the process that we are following?
BUILD_TAG, SVN_REVISION, etc are all environment variables that are present during a Jenkins build, and to use them in Ant, you would use them as any other environment variable from Ant
First, add a line:
<property environment="env"/>
Then you can reference any environment variable with this prefix, like:
${env.VAR_NAME}
So in your case, you'd do:
${env.BUILD_TAG}-${env.BUILD_NUMBER}-${env.BUILD_ID}-${env.SVN_REVISION}

Accessing the timestamp after PDE build

Am using ant to build my RCP application. The PDE headless build works well. However for some custom bundling of my artifacts, i need to access the timestamp that PDE uses while creating jars of my plugins and features.
Ex: com.test.app.1.0.0.201404091703.jar
I need to get the value 201404091703 from the PDE once the build is successful. Is this possible?
I tried with forceContextQualifier from the build.properties, but the problem with this is, everytime before the build starts i need to update this value manually (to some static value) and overriding of this global property (dynamically) using ANT is not possible.
Any suggestions is appreciated
You can specify -DforceContextQualifier=xxx as an argument to the org.eclipse.equinox.launcher_xxx run in your build.xml.
Update:
So, for example:
<buildnumber file="build.number"/>
<tstamp>
<format property="build.date" pattern="yyyyMMddHHmm" timezone="GMT"/>
</tstamp>
<property name="build.version" value="${build.date}-${build.number}"/>
<java fork="true" jar="${jar.launcher}">
<arg value="-DforceContextQualifier=${build.version}"/>
...
Sets the qualifier for a build to YYYYMMDDHHMM-num
The PDE headless build generates property files for each bundle with the current version numbers. In a custom callback (or else in your Ant build file) you can read such a property file and use the properties.
Search for the property generateVersionsLists in Eclipse Help.
http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.pde.doc.user%2Ftasks%2Fpde_version_qualifiers.htm

ANT job to invoke JDeveloper to create EAR file with specified deploy file

I was asked about the possibility of creating an ANT script that could be use to copy property files (associated to target environment), create an EAR file (perhaps using JDeveloper deploy file), and deploy that EAR file to target OC4J container.
I am asking if anyone ever successfully invoking JDeveloper automatically to create the EAR file by using specified 'deploy' file by using ANT? OR is it possible to by pass invoking JDeveloper at all. Is there any sample ANT code snippet to do so, or any information/hint that could be useful.
Thanks.
If you use ADF Business Components (BC) then you must use ojdeploy. Otherwise your BC will not get validated and your deployment will fail.
ojdeploy requires JDeveloper installation (ouch!) and will produce an EAR based on JDeveloper's deployment profiles .
(Although it's an old thread, I added something cos you never know.)
I would advise against using JDevelopers for creating an EAR file because I strongly believe that a build process must be autosufficient (i.e. as few external dependencies as possible).
Using Ant, you can simply use the Ear task (remember that the Ear task is a subtask of the Zip task, i.e. you can also use zipfileset inside the ear task).
I've never used OC4J but usually the deployment of an EAR file is just a matter of copying the file into the right directory (so a simple copy task would suffice).
Check out the ojdeploy command in the jdev\bin directory it will let you use JDeveloper's depoyment profiles from a command line.
I found that all the ant tasks used by jDeveloper are in the (default) directory: C:\Oracle\Middleware\jdeveloper\bin
I believe you can copy them to a build server and use them directly
They are the files it uses when you right click and select Deploy from the interface
You can build your own JDeveloper Deployment Profile Interpreter program and generate a Ant file from the Deployment Profile. I have done it before. Tim

Resources