Ant wsimport task failing - ant

I have a simple ant script to build my classes from a sdl. Unfortunately wsimport fails immediately. I suspect it has something to do with classpaths.
<taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport">
<classpath>
<pathelement location="${jaxws.lib.dir}/jaxws-tools.jar" />
</classpath>
</taskdef>
<wsimport
wsdl="${project.wsdl.dir}\some.wsdl"
destdir="${jaxws.output.dir}"
keep="false"
extension="true"
verbose="true"
wsdlLocation="http://localhost/wsdl"
target="2.1">
<depends file="${project.wsdl.dir}"/>
<produces dir="${jaxws.output.dir}"/>
</wsimport>
The this is the output it produces:
[wsimport] 15 Mar 2013 12:23:25 PM com.sun.xml.bind.v2.util.XmlFactory createDocumentBuilderFactory
[wsimport] SEVERE: null
[wsimport] java.lang.AbstractMethodError: javax.xml.parsers.DocumentBuilderFactory.setFeature(Ljava/lang/String;Z)V
[wsimport] at com.sun.xml.bind.v2.util.XmlFactory.createDocumentBuilderFactory(XmlFactory.java:176)
[wsimport] at com.sun.tools.xjc.reader.internalizer.DOMForest.(DOMForest.java:162)
[wsimport] at com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.resetSchema(SchemaCompilerImpl.java:215)
[wsimport] at com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.(SchemaCompilerImpl.java:114)
[wsimport] at com.sun.tools.xjc.api.XJC.createSchemaCompiler(XJC.java:72)
[wsimport] at com.sun.tools.ws.wscompile.WsimportOptions.(WsimportOptions.java:152)
[wsimport] at com.sun.tools.ws.wscompile.WsimportTool.(WsimportTool.java:89)
[wsimport] at com.sun.tools.ws.wscompile.WsimportTool.(WsimportTool.java:92)
[wsimport] at com.sun.tools.ws.ant.WsImport2.execute(WsImport2.java:848)
[wsimport] at com.sun.istack.tools.ProtectedTask.execute(ProtectedTask.java:103)
[wsimport] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:269)
[wsimport] at org.apache.tools.ant.Task.perform(Task.java:364)
[wsimport] at org.apache.tools.ant.Target.execute(Target.java:301)
[wsimport] at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:135)
[wsimport] at org.eclipse.ant.internal.launching.remote.InternalAntRunner.parseBuildFile(InternalAntRunner.java:192)
[wsimport] at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:401)
[wsimport] at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:138)
If I run the commandline create by the verbose logging, on wsimport, from the jax-ws bin directory everything works perfectly
[wsimport] command line: wsimport -d C:\Development\Source\ccs\jaxws-output -extension -verbose -target 2.1 C:\Development\Source\ccs\wsdl\some.wsdl -wsdllocation http://localhost/wsdl
I tried looking for a solution, but right now I am out of ideas

I think that one of the things tedious to use in the approach that you mention (taskdef and wsimport) is adding environment variables, especially when you want to use SSL and Basic authentication in your web service. I another hand, you can use the wsimport tool without define a new task. Something like that:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE project>
<project name="generate-client" default="main" basedir=".">
<property name="java.home"
value="X:\Software\jdk1.7.0_11" />
<property name="wsdl.location"
value="http://localhost/wsdl" />
<target name="main">
<exec executable="${java.home}\bin\wsimport.exe">
<arg line="${wsdl.location} -s src -Xdebug -verbose -Xnocompile" />
</exec>
</target>
</project>
Now that you have an idea, you can customize the output directory, add the target version ...

Related

Execute sqlplus from ant fails to find DYLD_LIBRARY_PATH

I'm attempting to run a SQL script from within Apache Ant using the execute tag for sqlplus.
<exec dir="src/sql" executable="sqlplus" failonerror="true" output="src/sql/test.sql.err">
<arg value="${db.login}"/>
<arg value="#test.sql"/>
</exec>
Sqlplus is working from the command line using the same arguments.
Ant, however returns:
dyld: Library not loaded: /ade/b/2649109290/oracle/sqlplus/lib/libsqlplus.dylib
For the command line I have set:
export DYLD_LIBRARY_PATH=/Applications/instantclient_11_2/
Is there an equivalent action I need to take for Ant to find the libraries?
One option is to give SQLcl a try.
It's the sql scripting engine from sqldev which is sqlplus , plus a lot more
http://www.oracle.com/technetwork/developer-tools/sqlcl/overview/sqlcl-index-2994757.html
The benefit is there there's no libraries it's self contained and uses the JDBC Thin driver for db connectivity.
Here's your ANT example..
<project name="sqlcl" basedir=".">
<property name="db.login" value="klrice/klrice"/>
<target name="sqlcl">
<exec dir="." executable="/Users/klrice/Downloads/sqlcl/bin/sql"
failonerror="true"
output="sql/test.sql.err">
<arg value="${db.login}"/>
<arg value="#sql/dual.sql"/>
</exec>
</target>
</project>
Then running...
$ ant sqlcl
Buildfile: /Users/klrice/build.xml
sqlcl:
BUILD SUCCESSFUL
Total time: 3 seconds
587211042:~ klrice$ more sql/test.sql.err
SQLcl: Release 17.4.0 Production on Wed Mar 07 21:59:54 2018
Copyright (c) 1982, 2018, Oracle. All rights reserved.
Last Successful login time: Wed Mar 07 2018 22:00:08 -05:00
Connected to:
Oracle Database 12c Standard Edition Release 12.1.0.2.0 - 64bit Production
login.sql found in the CWD. DB access is restricted for login.sql.
Adjust the SQLPATH to include the path to enable full functionality.
1
----------
1
Disconnected from Oracle Database 12c Standard Edition Release 12.1.0.2.0 - 64bit Production
Using the solution #kris-rice suggested, here is my implementation including checking for errors...
<!-- =================================================================== -->
<!-- load plsql tox -->
<!-- =================================================================== -->
<target name="compile.plsql.tox" description="compile plsql for tox">
<echo message="compile.plsql.tox --------------------"/>
<mkdir dir="tmp/log"/>
<exec dir="src/sql" executable="sql" failonerror="true" output="src/sql/tox.all.sql.err">
<arg value="${db.login.tox}"/>
<arg value="#tox.all.sql"/>
</exec>
<echo message="looking for plsql errors -------------------"/>
<exec dir="src/sql" executable="grep" failonerror="false" resultproperty="found">
<arg value="LINE/COL ERROR"/>
<arg value="tox.all.sql.err"/>
</exec>
<fail message="plsql compile errors">
<condition>
<equals arg1="${found}" arg2="0"/>
</condition>
</fail>
<echo message="looking for line item errors ---------------"/>
<exec dir="src/sql" executable="grep" failonerror="false" resultproperty="found">
<arg value="ERROR at"/>
<arg value="tox.all.sql.err"/>
</exec>
<fail message="sql compile errors">
<condition>
<equals arg1="${found}" arg2="0"/>
</condition>
</fail>
<echo message="compile.plsql.tox --------------------"/>
</target>
<!-- =================================================================== -->

build.xml to set date and time as file name

I want to set file name with date and time attached to it so I want to create file named as behat-20140913-195915.html however the example below sets the name as behat-yyyymmdd-hhiiss.html. Anyone know the solution to problem?
I followed this example
Note: These two don't work too: ${DSTAMP} ${TSTAMP}
<?xml version="1.0" encoding="UTF-8"?>
<project name="Sport" default="build-default" basedir=".">
<tstamp>
<format property="TODAY_MY" pattern="yyyymmdd-hhiiss" locale="en,UK" />
</tstamp>
<target name="build" description="Runs everything in order ..." depends="behat-bdd" />
<target name="behat">
<echo msg="Running Behat tests ..." />
<exec logoutput="true" checkreturn="true"
command="bin/behat -f progress --format html --out ${dir-report}/behat-${TODAY_MY}.html" dir="./" />
</target>
</project>
The tstamp task is documented in the ANT manual. It describes how the pattern format comes from the SimpleDateFormat object:
http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
I suggest trying the following:
Example
Buildfile: build.xml
build:
[echo] date: 20140913-203419
build.xml
<project name="demo" default="build">
<tstamp>
<format property="TODAY_MY" pattern="yyyyMMdd-HHmmss" locale="en,UK" />
</tstamp>
<target name="build">
<echo message="date: ${TODAY_MY}"/>
</target>
</project>
Software versions
$ ant -v
Apache Ant(TM) version 1.9.4 compiled on April 29 2014
$ java -version
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)

Executing who -m from ant

I am trying to execute the "who -m" command from Apache ant without success.
Here is my ant script:
<?xml version="1.0" encoding="UTF-8"?>
<project name="default" default="who.am.i">
<target name="who.am.i">
<exec executable="who" outputproperty="myOutput">
<arg value="-m"/>
</exec>
<echo message="I am = ${myOutput}"/>
</target>
</project>
The result is blank.
[echo] I am =
If I run exec without the argument, it displays the correct result:
<exec executable="who" outputproperty="myOutput">
</exec>
[echo] host.name = gary tty8 2014-02-03 12:04 (:0)
[echo] gary pts/0 2014-02-03 12:09 (:0)
[echo] gary pts/1 2014-02-03 12:23 (:0)
[echo] gary pts/2 2014-02-04 11:36 (:0)
[echo] gary pts/4 2014-02-05 13:27 (:0)
[echo] gary pts/7 2014-02-04 12:23 (:0)
[echo] gary pts/8 2014-02-06 12:44 (:0)
If I run the who -m command from a terminal it displays what I am looking for:
who -m
gary pts/8 2014-02-06 12:44 (:0)
Any ideas why ant is not accepting the -m argument?
Try executing as shell executable to see it that helps. It helps to invoke shell with exact unix command you want to run.
<exec executable="sh" outputproperty="myOutput">
<arg value="who -m"/>
</exec>
You don't mention which flavour of Unix you have, but on Solaris I get this error message when I try your task:
[echo] $ Must be attached to terminal for 'am I' option
In contrast, on OSX it appears to work, but says:
[echo] I am = mjc tty?? Feb 7 02:35
note the ?? - it's also not finding the terminal for the session.
I suspect that in your case it is silently failing for the same reason as the Solaris test - namely that the shell forked by Ant (i.e. by java) isn't associated with your terminal session.
(There may well be a workaround, but I'm not aware of it, and if there is one, it is unlikely to be portable.)
At the end of the day I decided to go another route.
In ~/.bashrc I added the following line:
who -m | awk '{print $5}' > ~/.whoami.out
And to make it global I just added it to /etc/bashrc
This will write to the ~/.whoami.out file every time I log into the remote system.
In my ant script I read the content of this file:
<?xml version="1.0" encoding="UTF-8"?>
<project name="default" default="default">
<target name="test.who.key">
<loadfile property="who.key" srcFile="${user.home}/.whoami.out" failonerror="false"/>
<condition property="who.cond">
<isset property="who.key"/>
</condition>
<condition property="who.cond2">
<not>
<isset property="who.key"/>
</not>
</condition>
</target>
<target name="init.who.key" depends="test.who.key" if="who.cond">
<echo message="WHO EXIST"/>
<property name="whoAmI" value="${who.key}"/>
</target>
<target name="init.not.who.key" depends="test.who.key" if="who.cond2">
<echo message="WHO DOES NOT EXIST"/>
<property name="whoAmI" value=""/>
</target>
<target name="default" depends="init.who.key, init.not.who.key">
<echo message="whoAmI = ${whoAmI}"/>
</target>
</project>

Ant & how to parse a properties file to echo back the values

I have a properties file that I want to echo out the values
<HSMKeys>
<Key domain="default" value="TestA" />
<Key domain="fixed" value="TestB" />
</HSMKeys>
as
[echo] domain=default value=TestA
[echo] domain=fixed value=TestB
How can I do this, ie loop over the properties file and have the two variables that would be in the echo.
I have tried the following
<for list="${HSMKeys.Key.domain}" param="domain">
<sequential>
<echo>domain=#{domain}</echo>
</sequential>
</for>
ie I can only get at one attribute value at a time, not both at once.
Thanks.
As #thekbb has stated this is not a properties file, however, ANT supports the parsing of XML files as properties.
<project name="demo" default="print">
<xmlproperty file="properties.xml"/>
<target name="print">
<echoproperties prefix="HSMKeys."/>
</target>
</project>
Produces the following output:
print:
[echoproperties] #Ant properties
[echoproperties] #Tue Dec 03 23:44:14 GMT 2013
[echoproperties] HSMKeys.Key=,
[echoproperties] HSMKeys.Key(domain)=default,fixed
[echoproperties] HSMKeys.Key(value)=TestA,TestB
May not be exactly what you need but has the advantage of not requiring additional jars like Ant-contrib.
That's not a properties file. Properties files are key/value pairs. How are you populating list?
a property file ant will understand will look like:
domain.default=TestA
domain.fixed=testB
I recommend avoiding ant-contrib at all costs... what are you really trying to do?
you could simply use echoproperties
<project name="test" default="echo" basedir=".">
<property file="build.properties" />
<target name="echo" >
<echoproperties prefix="domain."/>
</target>
</project>

Selenium Grid /Sauce Labs Plugin / Ant setup

I am trying to use ANT to start a Selenium Grid instance. Using the response found here, How can I run Selenium 2 Grid from an Ant build? , I was able to start the Grid successfully using the following build.xml
<project name="selenium-grid" default="launch-hub" basedir=".">
<property name="selenium.version" value="2.28.0"/>
<property name="sauce.version" value="1.0.8"/>
<path id="selenium.classpath">
<pathelement path="${basedir}/"/>
<fileset dir="${basedir}/">
<include name="selenium-server-standalone-${selenium.version}.jar"/>
<include name="sauce-grid-plugin-${sauce.version}.jar"/>
</fileset>
<pathelement path="${java.class.path}/"/>
</path>
<target name="launch-hub"
description="Launch Selenium Hub">
<java classname="org.openqa.grid.selenium.GridLauncher"
classpathref="selenium.classpath"
fork="true"
failonerror="true">
<arg value="-role"/>
<arg value="hub"/>
</java>
</target>
</project>
ant launch-hub
Moving on, I would like to use Sauce Labs Grid plug-in with the Selenium Grid which can be found here: https://github.com/rossrowe/sauce-grid-plugin/wiki
Following the wiki, I can start the two on my windows machine using the following from DOS
java -cp selenium-server-standalone-2.25.0.jar;sauce-grid-plugin-1.0.7.jar org.openqa.grid.selenium.GridLauncher -role hub -servlets com.saucelabs.grid.SauceOnDemandAdminServlet,com.saucelabs.grid.SauceOnDemandConsoleServlet
Now I want to incorporate the Sauce lab Servlets by adding to the target "launch-hub" to the arguments for the Sauce labs "servlets" (sorry having trouble posting the real code)
arg value="-servlets"
arg value="com.saucelabs.grid.SauceOnDemandAdminServlet,com.saucelabs.grid.SauceOnDemandConsoleServlet"
I relaunched using ant launch and here here is the error returned by windows:
launch-hub:
[java] 17 janv. 2013 10:58:40 org.openqa.grid.selenium.GridLauncher main
[java] INFO: Launching a selenium grid server
[java] 17 janv. 2013 10:58:50 org.openqa.grid.web.utils.ExtraServletUtil createServlet
[java] ATTENTION: The specified class : com.saucelabs.grid.SauceOnDemandAdminServlet cannot be instanciated com.sau
celabs.grid.SauceOnDemandAdminServlet
[java] 17 janv. 2013 10:58:50 org.openqa.grid.web.utils.ExtraServletUtil createServlet
[java] ATTENTION: The specified class : com.saucelabs.grid.SauceOnDemandConsoleServlet cannot be instanciated com.s
aucelabs.grid.SauceOnDemandConsoleServlet
[java] 2013-01-17 10:58:50.806:INFO:osjs.Server:jetty-7.x.y-SNAPSHOT
[java] 2013-01-17 10:58:50.866:INFO:osjsh.ContextHandler:started o.s.j.s.ServletContextHandler{/,null}
[java] 2013-01-17 10:58:50.876:INFO:osjs.AbstractConnector:Started SocketConnector#0.0.0.0:4444`enter code here
The Selenium Grid starts but without the servlets, thus no Saucelabs access
Any ideas?
Update Got it working using 1.0.7 of the sauce plugin. No go with version 1.0.8
I was able to get a Grid server running successfully with the Sauce Grid plugin by using your build.xml with the extra arguments, eg
<project name="selenium-grid" default="launch-hub" basedir=".">
<property name="selenium.version" value="2.25.0"/>
<property name="sauce.version" value="1.0.8"/>
<path id="selenium.classpath">
<pathelement path="${basedir}/"/>
<fileset dir="${basedir}">
<include name="selenium-server-standalone-${selenium.version}.jar"/>
<include name="sauce-grid-plugin-${sauce.version}.jar"/>
</fileset>
<pathelement path="${java.class.path}/"/>
</path>
<target name="launch-hub"
description="Launch Selenium Hub">
<java classname="org.openqa.grid.selenium.GridLauncher"
classpathref="selenium.classpath"
fork="true"
failonerror="true">
<arg value="-servlets"/>
<arg value="com.saucelabs.grid.SauceOnDemandAdminServlet,com.saucelabs.grid.SauceOnDemandConsoleServlet"/>
<arg value="-role"/>
<arg value="hub"/>
</java>
</target>
</project>
From looking at the Selenium Grid code, the error that appeared in the build output is generated when a ClassNotFoundException is thrown...can you check to see if the sauce-grid-plugin jar file is located in the ${basedir}?

Resources