How can I check a signed jar file using Ant? - java

I sign jar files with the Ant signjar task and now I want to test before deploy.
I can check with
jarsigner -verify sbundle.jar
but I do not know if it is possible to do the same with Ant?

An alternative would be to base your build on a maven script.
Maven does propose the jarsigner:verify plugin
If that is not a valid possibility, you still can use the Exec Ant task to directly call the jarsigner command.
If the return code is correctly set, you can add the attribute failonerror (Stop the build process if the command exits with a return code other than 0.)

The following Ant code can be used for verifying JAR-file signatures. The script will fail as soon as it encounters a JAR-file where the signature is not valid or where it is missing.
Note that ant-contrib is required for the for task.
<!-- Macro to verify whether or not a JAR file is signed -->
<macrodef name="verify-signatures">
<attribute name="filesetref" />
<sequential>
<for param="file">
<path>
<fileset refid="#{filesetref}" />
</path>
<sequential>
<echo message="Verifying signature on file: #{file}" />
<exec executable="jarsigner" failonerror="true">
<arg value="-verify" />
<arg value="#{file}" />
</exec>
<fail message="#{file} must be signed">
<condition>
<not>
<issigned file="#{file}" />
</not>
</condition>
</fail>
</sequential>
</for>
</sequential>
</macrodef>
<!-- Define the list of files to check -->
<fileset dir="p2repo" id="jarfiles">
<include name="**/*.jar" />
</fileset>
<!-- Verify signatures -->
<verify-signatures filesetref="jarfiles" />

Ant conditions offer "issigned".
"Test whether a jarfile is signed. If the name of the signature is passed, the file is checked for presence of that particular signature; otherwise the file is checked for the existence of any signature. It does not perform rigorous signature validation; it only looks for the presence of a signature.
This condition was added in Apache Ant 1.7."
From Ant conditions

You can use the VerifyJar Task in Ant to do this. Here is the link to Ant help
https://ant.apache.org/manual/Tasks/verifyjar.html
Sample code for Verifying multiple JAR files at once.
<verifyjar keystore="mykeystore" keypass="abc"
storepass="abc" alias="myalias">
<path>
<fileset dir="${build.dir}/signedjar" includes="**/*.jar" />
</path>
</verifyjar>

Based on #torkildr's answer.
It's possible to make macro pass nested path or fileset to ant-contrib for task.
<target name="verify-artifacts" description="Just an example of usage">
<verify-artifacts>
<fileset dir="${project.ear.dir}" includes="*.*ar"/>
</verify-artifacts>
</target>
<macrodef name="verify-artifacts">
<element name="artifact-path" implicit="true"/>
<sequential>
<for param="file">
<artifact-path/>
<sequential>
<verify-artifact file="#{file}"/>
</sequential>
</for>
</sequential>
</macrodef>
<macrodef name="verify-artifact">
<attribute name="file"/>
<attribute name="alias" default="${artifact.sign.keystore.alias}"/>
<attribute name="keystore" default="${artifact.sign.keystore.path}"/>
<attribute name="password" default="${artifact.sign.keystore.password}"/>
<sequential>
<if>
<istrue value="${artifact.sign.enabled}"/>
<then>
<echo message="Trying to verify #{file} with alias #{alias} from #{keystore}"/>
<required-macro-param value="#{alias}" prop="artifact.sign.keystore.alias"/>
<required-macro-param value="#{keystore}" prop="artifact.sign.keystore.path"/>
<required-macro-param value="#{password}" prop="artifact.sign.keystore.password"/>
<fail message="Keystore path '#{keystore}' not found">
<condition>
<not><available file="#{keystore}" type="file"/></not>
</condition>
</fail>
<fail message="Artifact '#{file}' not found">
<condition>
<not><available file="#{file}" type="file"/></not>
</condition>
</fail>
<!-- jarsigner -verify -keystore #{keystore} -storepass #{password} #{file} #{alias} -->
<exec executable="jarsigner" failonerror="true">
<arg value="-verify"/>
<arg value="-keystore"/>
<arg value="#{keystore}"/>
<arg value="-storepass"/>
<arg value="#{password}"/>
<arg value="#{file}"/>
<arg value="#{alias}"/>
</exec>
</then>
</if>
</sequential>
</macrodef>
<macrodef name="required-macro-param">
<attribute name="prop"/>
<attribute name="value"/>
<sequential>
<!--<echo message="#{value}"/>-->
<fail message="You must set property '#{prop}'">
<condition>
<and>
<or>
<equals arg1="#{value}" arg2=""/>
<matches string="#{value}" pattern="^\$\{.*?\}$"/>
</or>
<!--<not><isset property="#{prop}"/></not>-->
</and>
</condition>
</fail>
</sequential>
</macrodef>
<macrodef name="sign-artifact">
<attribute name="file"/>
<attribute name="alias" default="${artifact.sign.keystore.alias}"/>
<attribute name="keystore" default="${artifact.sign.keystore.path}"/>
<attribute name="password" default="${artifact.sign.keystore.password}"/>
<sequential>
<if>
<istrue value="${artifact.sign.enabled}"/>
<then>
<echo message="Trying to sign #{file} with alias #{alias} from #{keystore}"/>
<required-macro-param value="#{alias}" prop="artifact.sign.keystore.alias"/>
<required-macro-param value="#{keystore}" prop="artifact.sign.keystore.path"/>
<required-macro-param value="#{password}" prop="artifact.sign.keystore.password"/>
<fail message="Keystore path '#{keystore}' not found">
<condition>
<not><available file="#{keystore}" type="file"/></not>
</condition>
</fail>
<fail message="Artifact '#{file}' not found">
<condition>
<not><available file="#{file}" type="file"/></not>
</condition>
</fail>
<signjar jar="#{file}" alias="#{alias}" keystore="#{keystore}" storepass="#{password}"/>
<fail message="Signature check failed">
<condition>
<not><issigned file="#{file}" name="#{alias}"/></not>
</condition>
</fail>
</then>
</if>
</sequential>
</macrodef>
<macrodef name="sign-artifacts">
<element name="artifact-path" implicit="true"/>
<sequential>
<for param="file">
<artifact-path/>
<sequential>
<sign-artifact file="#{file}"/>
</sequential>
</for>
</sequential>
</macrodef>
<property name="artifact.sign.enabled" value="true"/>
<property name="artifact.sign.keystore.alias" value="alias"/>
<property name="artifact.sign.keystore.path" value="keystore.jks"/>
<property name="artifact.sign.keystore.password" value="pwd"/>

Related

Javadoc task in Ant build fails

I'm receiving an error message from Ant when I try to run the Javadoc ant task.
"BUILD FAILED
/data/data/com.termux/files/home/LearnJava/Observer/build.xml:39: No source files, no packages and no modules have been specified."
The build files reside at:
https://github.com/Fernal73/LearnJava/blob/master/Observer/build.properties
version=1.0.0
main.class=com.javacodegeeks.patterns.observerpattern.TestObserver
main.class1=com.javacodegeeks.patterns.observerpattern.Test
cs.properties=../checkstyle.properties
gformat.properties=../gformat.properties
ant.build.javac.source=1.7
ant.build.javac.target=1.7
packages=com.javacodegeeks.patterns.observerpatern.*
and
https://github.com/Fernal73/LearnJava/blob/master/Observer/build.xml
<?xml version="1.0"?>
<project name="Observer" default="main"
basedir=".">
<property file = "build.properties"/>
<property file = "${cs.properties}"/>
<property file = "${gformat.properties}"/>
<!-- Sets variables which can later be used. -->
<!-- The value of a property is accessed via ${} -->
<property name="src.dir" location="." />
<property name="build.dir" location="." />
<property name="dist.dir" location="dist" />
<property name="docs.dir" location="docs" />
<taskdef resource="${cs.taskdef.resource}"
classpath="../${cs.jar}"/>
<!-- Deletes the existing build, docs and dist directory-->
<target name="clean">
<delete>
<fileset dir="." includes="**/*.class"/>
</delete>
<delete dir="${docs.dir}" />
<delete dir="${dist.dir}" />
</target>
<!-- Creates the build, docs and dist directory-->
<target name="makedir">
<mkdir dir="${docs.dir}" />
<mkdir dir="${dist.dir}" />
</target>
<!-- Compiles the java code (including the usage of library for JUnit -->
<target name="compile" depends="clean, makedir,gformat,checkstyle">
<javac includeantruntime="false" srcdir="${src.dir}" destdir="${build.dir}">
<compilerarg value="-Xlint:-options"/>
</javac>
</target>
<!-- Creates Javadoc -->
<target name="docs" depends="compile">
<javadoc packagenames="${packages}" additionalparam="-Xdoclint:none"
sourcepath="${src.dir}"
destdir="${docs.dir}">
<!-- Define which files / directory should get included, we include all -->
<fileset dir="${src.dir}">
<include name="*.java" />
</fileset>
</javadoc>
</target>
<target name="manifest">
<tstamp/>
<manifest file="manifest.mf">
<attribute name="Built-By" value="${user.name}"/>
<section name="common">
<attribute name="Specification-Title" value="${ant.project.name}"/>
<attribute name="Specification-Version" value="${version}"/>
<attribute name="Specification-Vendor" value=""/>
<attribute name="Implementation-Title" value=""/>
<attribute name="Implementation-Version" value="${build} ${TODAY}"/>
<attribute name="Implementation-Vendor" value=""/>
</section>
<attribute name="Main-Class" value="${main.class}" />
</manifest>
</target>
<!--Creates the deployable jar file -->
<target name="jar" depends="compile,manifest">
<jar destfile="${dist.dir}\${ant.project.name}.jar" basedir="${build.dir}" includes="**/*.class"
manifest="manifest.mf">
</jar>
</target>
<target name="run" >
<description>Run target</description>
<java classname="${main.class}">
<classpath>
<pathelement location="${dist.dir}\${ant.project.name}.jar"/>
<pathelement path="${java.class.path}"/>
</classpath>
</java>
</target>
<target name="gformat">
<exec executable="find" dir="${basedir}"
failonerror="true" outputproperty="sources">
<arg line=" . -type f -name '*.java'"/>
</exec>
<echo message="About to format ...: ${sources}"/>
<java classname="${gformat.main.class}">
<arg line=" -i ${sources}"/>
<classpath>
<pathelement location="../${gformat.jar}"/>
<pathelement path="${java.class.path}"/>
</classpath>
</java>
</target>
<target name="checkstyle">
<first id="checkstylefile">
<fileset dir=".." includes="${cs.config}"/>
</first>
<checkstyle config="${toString:checkstylefile}"
classpath="../${cs.jar}"
failOnViolation="false" properties="${cs.properties}">
<fileset dir="${src.dir}" includes="**/*.java"/>
<formatter type="plain"/>
<formatter type="plain" toFile="${cs.output}"/>
</checkstyle>
</target>
<target name="main" depends="compile, jar, docs">
<description>Main target</description>
</target>
</project>
respectively.
My other projects on the repository have similar configurations.
They work as expected.
Am I missing something obvious?
I did miss something obvious. An extra 't' in the property packages. Evidently, I'm going to need two sets of eyes for this or a fresh set, a few hours later!
NOW, how do I close this?
I think the problem is in following part:
<fileset dir="${src.dir}">
<include name="*.java" />
</fileset>
In Ant "*.java" means all files with names matching *.java. This does not search in subdirectories.
To include all subdirectories you must specify:
<fileset dir="${src.dir}">
<include name="**/*.java" />
</fileset>
But since you already specified the sourcePath attribute I'm wondering if you can't just remove the fileset element as ant will add **/*.java by default.

Configuration required for ant xml to build correct jar using java 1.8.0_40 and ant 1.9.0

I am trying to build jar for my project using jdk 1.8.0_40 and ant version 1.9.0, jar is getting build but while converting this jar to .exe, it is not able to find main class as I have correctly mentioned my main class.I am using eclipse Mar Version: Mars.2 Release (4.5.2).
Earlier I was using jdk 1.7.0_79 version and ant 1.8.4 and everything was working fine.
I am facing issue while upgrading from jdk 1.7.0_79 to jdk 1.8.0_40.
Below is my ant xml which are using to build my jar.Let me know if any configuration is required for java 1.8 to build proper jar.
<property name="jar.name" value="SAFAL.jar" />
<property name="source.root" value="src" />
<property name="class.root" value="bin" />
<property name="lib.dir" value="lib" />
<property name="jar.dir" value="C:\D\SAFAL-Exe" />
<property name="Main-Class" value="com.sungard.ktt.main.SAFALEval" />
<property name="conf.pkj" value="com/sungard/ktt/business/configurations" />
<property name="img.pkj" value="com/sungard/ktt/business/images" />
<path id="project.class.path">
<pathelement location="${class.root}" />
<fileset dir="${lib.dir}">
<include name="*.jar" />
</fileset>
</path>
<target name="clean" description="cleans up build structures">
<delete dir="${class.root}" />
<delete file="${jar.dir}/${jar.name}" />
</target>
<target name="prepare" description="sets up build structures">
<mkdir dir="${class.root}" />
</target>
<target name="compile" depends="prepare" description="Compiles all java classes">
<javac srcdir="${source.root}" destdir="${class.root}" debug="on" optimize="off" deprecation="on" source="1.8" target="1.8" includeantruntime = "false">
<classpath refid="project.class.path" />
</javac>
<mkdir dir="${class.root}/${conf.pkj}" />
<mkdir dir="${class.root}/${img.pkj}" />
<copy todir="${class.root}/${conf.pkj}">
<fileset dir="${source.root}/${conf.pkj}" />
</copy>
<copy todir="${class.root}/${img.pkj}">
<fileset dir="${source.root}/${img.pkj}" />
</copy>
</target>
<target name="jar" depends="compile">
<delete file="${jar.dir}/${jar.name}" quiet="true" failonerror="false" />
<jar destfile="${jar.dir}/${jar.name}">
<fileset dir="${class.root}" includes="**/*.*" />
<fileset dir="${source.root}" includes="**/api/*.java,**/api/vo/*.java"/>
<zipgroupfileset dir="${lib.dir}" />
<manifest>
<attribute name="Main-Class" value="${Main-Class}" />
<attribute name="Class-Path" value="." />
</manifest>
</jar>
</target>
<target name="run">
<java fork="true" classname="${Main-Class}">
<classpath>
<path location="./${jar.name}" />
</classpath>
</java>
</target>
In your java task you are using ./${jar.name} as the location of your jar - this is relying on the current directory being set correctly. All the rest of your code uses ${jar.dir}/${jar.name} as the path for the jar, so change the java task to do the same:
<target name="run">
<java fork="true" classname="${Main-Class}">
<classpath>
<path location="${jar.dir}/${jar.name}" />
</classpath>
</java>
</target>

how to replicate "ant run" to execute a Glassfish ACC client with appclient

How do I run the appclient outside of the IDE? While it seems possible to run stand-alone JNDI lookup apps from the CLI with appclient, it doesn't appear to work for ACC clients. However, it should be possible:
Running an Application Client
Using the appclient Script To run an application client,
you can launch the ACC using the appclient script,
whether or not Java Web Start is enabled.
GlassFish Server Open Source Edition
Application Development Guide
Release 4.0
Developing Java Clients 10-15
page 186
Steps:
1.) created an #Remote interface as a Java SE library API
2.) created an Enterprise Application with an ejb module; add the interface API
3.) in the ejb module, implement the #Remote interface
4.) create an ACC app; add the interface API; add to the Enterprise Application
5.) insert the ejb from the IDE
6.) deploy the EAR and then run the ACC client from the IDE
This is adapted from Creating and Running an Application Client on the GlassFish Server.
running with ant, "ant run" from the CLI:
-run:
[java] 2
run:
BUILD SUCCESSFUL
Total time: 28 seconds
thufir#dur:~/NetBeansProjects/SingletonACC$
which is the correct output, in this case. (Each time the client runs, the integer increases by one.)
I've looked through the ant files, but wasn't able to decipher what "ant run" does in this case:
<!--
=================
EXECUTION SECTION
=================
-->
<target depends="dist,run-deploy,-as-retrieve-option-workaround,-init-run-macros,-run-pregfv3,-run" description="Run a main class." name="run"/>
<target if="j2ee.appclient.tool.args" name="-run-pregfv3">
<carproject:run-appclient-pregfv3/>
</target>
<target name="-run" unless="j2ee.appclient.tool.args">
<carproject:run-appclient/>
</target>
<target depends="dist,run-deploy,-as-retrieve-option-workaround,-init-run-macros,-run-single-pregfv3,-run-single" description="Run a single class." name="run-single"/>
<target depends="dist,run-deploy,-as-retrieve-option-workaround,-init-run-macros" name="-run-single" unless="j2ee.appclient.tool.args">
<fail unless="run.class">Must select one file in the IDE or set run.class</fail>
<carproject:run-appclient serverparams="${j2ee.appclient.tool.jvmoptions.class}${run.class}"/>
</target>
<target depends="dist,run-deploy,-as-retrieve-option-workaround,-init-run-macros" if="j2ee.appclient.tool.args" name="-run-single-pregfv3">
<fail unless="run.class">Must select one file in the IDE or set run.class</fail>
<carproject:run-appclient-pregfv3/>
</target>
<target depends="init" name="-init-run-macros">
<macrodef name="run-appclient" uri="http://www.netbeans.org/ns/car-project/1">
<attribute default="${application.args.param}" name="args"/>
<attribute default="${j2ee.appclient.tool.jvmoptions}${client.jar}" name="serverparams"/>
<element name="customize" optional="true"/>
<sequential>
<java dir="${basedir}" fork="true" jar="${client.jar}">
<jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
<jvmarg line="#{serverparams}"/>
<jvmarg line="${run.jvmargs.param}"/>
<arg line="#{args}"/>
<syspropertyset>
<propertyref prefix="run-sys-prop."/>
<mapper from="run-sys-prop.*" to="*" type="glob"/>
</syspropertyset>
<env key="APPCPATH" path="${javac.classpath}"/>
<sysproperty key="java.system.class.loader" value="org.glassfish.appclient.client.acc.agent.ACCAgentClassLoader"/>
<customize/>
</java>
</sequential>
</macrodef>
<macrodef name="run-appclient-pregfv3" uri="http://www.netbeans.org/ns/car-project/1">
<element name="customize" optional="true"/>
<sequential>
<java classname="${j2ee.appclient.tool.mainclass}" fork="true">
<jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
<jvmarg line="${j2ee.appclient.tool.jvmoptions}"/>
<jvmarg line="${run.jvmargs.param}"/>
<arg line="${j2ee.appclient.tool.args}"/>
<arg line="-client ${client.jar}"/>
<arg line="${application.args.param}"/>
<classpath>
<path path="${j2ee.platform.classpath}:${j2ee.appclient.tool.runtime}"/>
</classpath>
<syspropertyset>
<propertyref prefix="run-sys-prop."/>
<mapper from="run-sys-prop.*" to="*" type="glob"/>
</syspropertyset>
<customize/>
</java>
</sequential>
</macrodef>
</target>
<target if="j2ee.appclient.mainclass.args" name="-as-retrieve-option-workaround" unless="j2ee.clientName">
<property name="client.jar" value="${dist.dir}/SingletonACCClient.jar"/>
<sleep seconds="3"/>
<copy failonerror="false" file="${wa.copy.client.jar.from}/SingletonACC/SingletonACCClient.jar" todir="${dist.dir}"/>
<copy failonerror="false" flatten="true" todir="${dist.dir}/">
<fileset dir="${wa.copy.client.jar.from}/SingletonACC" includes="**/SingletonACCClient.jar"/>
</copy>
<copy flatten="true" todir="${dist.dir}/SingletonACCClient">
<fileset dir="${wa.copy.client.jar.from}/SingletonACC" includes="**/*.*ar"/>
</copy>
<copy failonerror="false" flatten="false" todir="${dist.dir}/SingletonACCClient">
<fileset dir="${dist.dir}/gfdeploy/SingletonACC" includes="**/*.jar"/>
</copy>
</target>
<target name="pre-run-deploy">
<!-- Empty placeholder for easier customization. -->
<!-- You can override this target in the ../build.xml file. -->
</target>
<target name="post-run-deploy">
<!-- Empty placeholder for easier customization. -->
<!-- You can override this target in the ../build.xml file. -->
</target>
<target name="-pre-nbmodule-run-deploy">
<!-- Empty placeholder for easier customization. -->
<!-- This target can be overriden by NetBeans modules. Don't override it directly, use -pre-run-deploy task instead. -->
</target>
<target name="-post-nbmodule-run-deploy">
<!-- Empty placeholder for easier customization. -->
<!-- This target can be overriden by NetBeans modules. Don't override it directly, use -post-run-deploy task instead. -->
</target>
<target name="-run-deploy-am">
<!-- Task to deploy to the Access Manager runtime. -->
</target>
<target depends="init,compile,dist,pre-run-deploy,-pre-nbmodule-run-deploy,-run-deploy-nb,-init-deploy-ant,-deploy-ant,-run-deploy-am,-post-nbmodule-run-deploy,post-run-deploy,-do-update-breakpoints" name="run-deploy"/>
<target if="netbeans.home" name="-run-deploy-nb">
<nbdeploy clientUrlPart="${client.urlPart}" debugmode="false" forceRedeploy="${forceRedeploy}"/>
</target>
<target name="-init-deploy-ant" unless="netbeans.home">
<property name="deploy.ant.archive" value="${dist.jar}"/>
<property name="deploy.ant.resource.dir" value="${resource.dir}"/>
<property name="deploy.ant.enabled" value="true"/>
</target>
<target depends="init,-run-undeploy-nb,-init-deploy-ant,-undeploy-ant" name="run-undeploy"/>
<target if="netbeans.home" name="-run-undeploy-nb">
<fail message="Undeploy is not supported from within the IDE"/>
</target>
<target depends="run-deploy,-init-display-browser,-display-browser-nb,-display-browser-cl" name="run-display-browser"/>
<target if="do.display.browser" name="-init-display-browser">
<condition property="do.display.browser.nb">
<isset property="netbeans.home"/>
</condition>
<condition property="do.display.browser.cl">
<and>
<isset property="deploy.ant.enabled"/>
<isset property="deploy.ant.client.url"/>
</and>
</condition>
</target>
<target if="do.display.browser.nb" name="-display-browser-nb">
<nbbrowse url="${client.url}"/>
</target>
<target if="do.display.browser.cl" name="-get-browser" unless="browser">
<condition property="browser" value="rundll32">
<os family="windows"/>
</condition>
<condition else="" property="browser.args" value="url.dll,FileProtocolHandler">
<os family="windows"/>
</condition>
<condition property="browser" value="/usr/bin/open">
<os family="mac"/>
</condition>
<property environment="env"/>
<condition property="browser" value="${env.BROWSER}">
<isset property="env.BROWSER"/>
</condition>
<condition property="browser" value="/usr/bin/firefox">
<available file="/usr/bin/firefox"/>
</condition>
<condition property="browser" value="/usr/local/firefox/firefox">
<available file="/usr/local/firefox/firefox"/>
</condition>
<condition property="browser" value="/usr/bin/mozilla">
<available file="/usr/bin/mozilla"/>
</condition>
<condition property="browser" value="/usr/local/mozilla/mozilla">
<available file="/usr/local/mozilla/mozilla"/>
</condition>
<condition property="browser" value="/usr/sfw/lib/firefox/firefox">
<available file="/usr/sfw/lib/firefox/firefox"/>
</condition>
<condition property="browser" value="/opt/csw/bin/firefox">
<available file="/opt/csw/bin/firefox"/>
</condition>
<condition property="browser" value="/usr/sfw/lib/mozilla/mozilla">
<available file="/usr/sfw/lib/mozilla/mozilla"/>
</condition>
<condition property="browser" value="/opt/csw/bin/mozilla">
<available file="/opt/csw/bin/mozilla"/>
</condition>
</target>
<target depends="-get-browser" if="do.display.browser.cl" name="-display-browser-cl">
<fail unless="browser">
Browser not found, cannot launch the deployed application. Try to set the BROWSER environment variable.
</fail>
<property name="browse.url" value="${deploy.ant.client.url}${client.urlPart}"/>
<echo>Launching ${browse.url}</echo>
<exec executable="${browser}" spawn="true">
<arg line="${browser.args} ${browse.url}"/>
</exec>
</target>
<target depends="dist" name="verify">
<nbverify file="${dist.jar}"/>
</target>
<target depends="init,compile-single" name="run-main">
<fail unless="run.class">Must select one file in the IDE or set run.class</fail>
<carproject:java classname="${run.class}"/>
</target>
<target depends="init" if="netbeans.home" name="-do-update-breakpoints">
<carproject:nbjpdaappreloaded/>
</target>
How can I replicate "ant run" outside of the IDE?
note that SingletonAcc is deployed individually, even though it's also part of the SingletonQueue Enterprise Application, which also has an appclient.
thufir#dur:~/NetBeansProjects/SingletonACC$
thufir#dur:~/NetBeansProjects/SingletonACC$ /home/thufir/glassfish-4.1/glassfish/bin/asadmin list-applications
SingletonQueue <ear, appclient, ejb>
SingletonACC <appclient>
Command list-applications executed successfully.
thufir#dur:~/NetBeansProjects/SingletonACC$
You can enable verbose logging in ant so you can see what it is actually executing:
In NetBeans go to Options -> Tools -> Java -> Ant and set the Verbosity Level to Debug.
It looks like ant just deploys the appclient (EntAppClient.jar) on GlassFish and then runs the file EntAppClientClient.jar (notice the double Client) with some parameters similar to this:
/java/jdk1.7.0/jre/bin/java.exe
-Xbootclasspath/p:/NetBeans/enterprise/modules/ext/javaee6-endorsed/javax.annotation.jar;/NetBeans/enterprise/modules/ext/javaee6-endorsed/jaxb-api-osgi.jar;/NetBeans/enterprise/modules/ext/javaee6-endorsed/webservices-api-osgi.jar
-Djava.endorsed.dirs=/glassfish410/glassfish/lib/endorsed;/glassfish410/glassfish/modules/endorsed
-javaagent:/glassfish410/glassfish/lib/gf-client.jar=mode=acscript,arg=-configxml,arg=/glassfish410/glassfish/domains/domain1/config/glassfish-acc.xml,client=jar=dist/EntAppClientClient.jar
-Djava.system.class.loader=org.glassfish.appclient.client.acc.agent.ACCAgentClassLoader
-jar /EntAppClient/dist/EntAppClientClient.jar
Hope this helps :)

Why does not ant delete task work?

I have this ant script:
<sequential>
<echo message="Deleting needed folder" />
<property name="bigPathToFolder" value="${basePath}/pathToFolder" />
<delete dir="bigPathToFolder" quiet="false"/>
<echo message="Delete success" />
</sequential>
In console I see Deleting needed folder and after Delete success, but the content of the folder and folder don't change.
What did I do wrong?
replace
<delete dir="bigPathToFolder" quiet="false"/>
to
<delete dir="${bigPathToFolder}" quiet="false"/>
You can use if task available from ant-contrib to do file existance check at path you are looking & run a delete like below:
<if>
<available file="${bigPathToFolder}"/>
<then>
<delete dir="${bigPathToFolder}" quiet="false"/>
<echo message="Delete success" />
</then>
<else>
<echo message="File Not found at path : ${bigPathToFolder}" />
</else>
</if>

Using Ant condition tag

I want to do something like this
<target name="init" description="Create build directories.
>
<mkdir dir="bin" />
<mkdir dir="dist" />
<!-- Check for the presence of dependent JARs -->
<condition property="dependent.files.available">
<and>
<available file="../../xx.jar" />
<available file="../../yy.jar" />
</and>
</condition>
</target>
<!--- Compile -->
<target name="compile" depends="init" description="Compile java sources
and create classes">
<if>
<isset property="dependent.files.available"/>
<then>
<javac srcdir="src" destdir="bin" classpathref="ext_jar_classpath"/>
</then>
<else>
<echo message="Either xx.jar or yy.jar not found"/>
</else>
</if>
</target>
When I tried to compile the code it gave me the following error
Problem: failed to create task or type if
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
It it the correct way of doing it?
You need to have the ant-contrib jar visible at runtime, or configure it correctly as described in the link.
The thing boils down to have Ant load the task definition, so if you put ant-contrib in ant/lib, you just need
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
Just a suggestion. You can do the same thing with ant 1.9.1 onwards using if/unless without ant-contrib (http://ant.apache.org/manual/targets.html)
Your targets would be
<target name="init" description="Create build directories.
>
<mkdir dir="bin" />
<mkdir dir="dist" />
<!-- Check for the presence of dependent JARs -->
<condition property="dependent.files.available">
<and>
<available file="../../xx.jar" />
<available file="../../yy.jar" />
</and>
</condition>
</target>
<!--- Compile -->
<target name="compile" depends="init" description="Compile java sources
and create classes" if="dependent.files.available">
<javac srcdir="src" destdir="bin" classpathref="ext_jar_classpath"/>
</target>

Categories