ant sql task error: No suitable Driver - ant

I am using the following ant sql task and its throwing "No suitable Driver exception" java.sql.SQLException: No suitable Driver for
at org.apache.tools.ant.taskdefs.JDBCTask.getConnection(JDBCTask.java:370)
at org.apache.tools.ant.taskdefs.SQLExec.getConnection(SQLExec.java:961)
at org.apache.tools.ant.taskdefs.SQLExec.execute(SQLExec.java:628)
I have verified that the ojdbc6 jar is present in the location and echoing classpath also includes the location of jar.
<property name="jdbc.driver.jar" value="${wl.home}/server/lib/ojdbc6.jar"/>
<property name="jdbc.driver" value="oracle.jdbc.OracleDriver"/>
<sql driver="${jdbc.driver}"
url="${datasource_url}"
userid="${datasource_user}"
password="${datasource_password}"
src="${sqlfile}"
output="${outfile}"
print="true"
onerror="abort"
expandProperties="true">
<classpath>
<pathelement location="${jdbc.driver.jar}"/>
</classpath>
</sql>

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

xmltask error when replacing node in xml file

I got an error when runnning target replace to xmltask:
C:\Tools\build.xml:432: The following error occurred while executing this line:
C:\Tools\build.xml:408: Failed to specify text in replace
the problem is that my coworker had no issues running the same code on his computer. I can't figure out why I got the error while my coworker didn't.
the part of build.xml is as follow:
<target name="replace" depends="init" description="replace node.">
<xmltask source="${my-file}" dest="${my-file}">
<replace path=
"/*[local-name()='server']
/*[local-name()='profile']
/*[local-name() = 'subsystem'][1]"
withFile="${devlogfile}"/>
</xmltask>
</target>
<target name="init">
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="${ant.lib.dir}/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask">
<classpath>
<pathelement path="${ant.lib.dir}/xmltask.jar"/>
</classpath>
</taskdef>
</target>
the part of property file is as follow:
my-file=c:/old.xml
devlogfile=c:/new.xml
[Converted from the comments section]
Did you compare the jdk and classpath in the case of your co-worker and yourself ? It's impossible to tell with the information given so far, but it's possible you are using different parsers.
The error message suggests Ant doesn't find the devlogfile file itself.
Are you sure the properties file is passed properly to your ant runtime ? How are you passing it ?

How to specify oracle odbjc.jar in Liquibase ant configuration

I have following ant configuration:
<project name="pcebuild" basedir="." default="updateDatabase" xmlns:liquibase="antlib:liquibase.integration.ant" >
<taskdef resource="liquibase/integration/ant/antlib.xml" uri="antlib:liquibase.integration.ant">
<classpath path="c:\Users\artur.skrzydlo\Documents\liquibase-3.3.2-bin\liquibase.jar"/>
</taskdef>
<property name="liquiChangeLogFile" value="${basedir}/liquibase/db.changelog-master.xml"/>
<property name="db.driver" value="oracle.jdbc.OracleDriver"/>
<property name="db.url" value="jdbc:oracle:thin:#websph:1521:XE"/>
<target name="updateDatabase" description="Updates database with new changes using Liquibase">
<liquibase:updateDatabase changeLogFile="${liquiChangeLogFile}" >
<liquibase:database driver="${db.driver}" url="${db.url}" user="${db.user}" password="${db.pasword}"/>
</liquibase:updateDatabase>
</target>
</project>
After running this task I get an error :
Class not found: oracle.jdbc.OracleDriver
According to documentation :
driver The fully qualified class name of the JDBC driver.
I suppose that this error may rise because there is no place where I place classpath to my ojdbc.jar file. I am able to run this update command from command line, however there I can specify "classpath" argument which point to my ojdbc.jar file. And I don's see any place in this ant task definition where could i place it such a path. How can I do this ? What am I doing wrong ?
In your <liquibase:updateDatabase> tag you can have a classpathref attribute. So I have something like this:
<path id="driver.classpath">
<filelist files="${classpath}" />
</path>
...
<liquibase:updateDatabase
databaseref="main-schema"
changelogfile="${changeLogFile}"
classpathref="driver.classpath"
logLevel="debug"
>
...
And ${classpath} is an Ant property, set in a properties file:
classpath: /Users/me/place/lib/classes12.jar

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

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>

How to get Sonar to export test stats?

I have the following Sonar Ant target defined:
<target name='sonar'>
<property name='sonar.sources' value='${src.dir}'/>
<property name='sonar.tests' value='${test.src.dir}'/>
<property name='sonar.binaries' value='build/classes'/>
<path id='jars'>
<fileset dir='${env.JAVA_HOME}/jre/lib' includes='*.jar'/>
<fileset dir='build/lib/test' includes='*.jar'/>
</path>
<pathconvert property='sonar.libraries' refid='jars' pathsep=','/>
<exec executable='p4' outputproperty='p4.P4CLIENT'>
<arg value='set'/>
<arg value='P4CLIENT'/>
</exec>
<propertyregex
property='p4client'
input='${p4.P4CLIENT}'
regexp='P4CLIENT=([^ ]+) *.*'
replace='\1'/>
<propertyregex
property='sonar.timestamp'
input='${build.time}'
regexp='_'
replace='T'/>
<sonar:sonar key='com.netflix:${module.name}' version='${p4client}#${sonar.timestamp}' xmlns:sonar='antlib:org.sonar.ant'/>
<property name='sonar.dynamicAnalysis' value='reuseReports'/>
<property name='sonar.emma.reportPath' value='${coverage.dir}'/>
</target>
When I run 'ant sonar' and bring up Sonar in my browser, I see info about the classes in the src directory, but nothing about the stuff in the test directory.
If I add ${test.src.dir} to sonar.sources and not set sonar.tests, I see some info about the test classes, but Sonar still reports 0 Test Successes.
How do I get it so I can drill down to each test method and their stats?
For anyone else that runs across this issue, I finally got Sonar to report on our Emma Code coverage. The first problem was that the Emma plugin did not come with the version of Sonar I was using (3.1.1). I had to download it and install it to the extensions/plugins directory of Sonar and restart it.
Then I had to set the following properties in my build.xml:
<property name="sonar.core.codeCoveragePlugin" value="emma" />
<property name="sonar.emma.reportPath" value="${coverage.dir}" />
After this, I atleast saw the following output after running the Sonar ant task:
[sonar:sonar] 13:41:49.705 WARN org.sonar.INFO - No coverage (*.ec) file found in /my/local/path
[sonar:sonar] 13:41:49.708 WARN org.sonar.INFO - No metadata (*.em) file found in /my/local/path
After some digging, I found that inside of the Sonar Emma plugin, it is hard-coded to look for a .ec (coverage) file and a .em (metadata) file. Unfortunately, my coverage file had a .emma extension as did my metadata file and I was unable to rename them as it would break other functionality. So I wrote the following Ant task to copy the files to match the naming standard that the Sonar Emma plugin expects.
<target name="createEmmaFilesWithSonarNamingStandard" depends="defineAntContribTasks">
<if>
<available file="${coverage.dir}/metadata.emma" />
<then>
<copyfile src="${coverage.dir}/metadata.emma" dest="${coverage.dir}/metadata.em" />
</then>
</if>
<if>
<available file="${coverage.dir}/coverage.emma" />
<then>
<copyfile src="${coverage.dir}/coverage.emma" dest="${coverage.dir}/coverage.ec" />
</then>
</if>
</target>
After running this again, I came across a new problem:
org.sonar.api.utils.SonarException: java.io.IOException: cannot read [/my/local/path/build/coverage/metadata.em]: created by another EMMA version [2.0.5312]
After some more digging, I found that the Sonar Emma 1.0.1 plugin was compiled against Emma 2.0.5312 and the Sonar Emma 1.1 and 1.2.x against Emma version 2.1.5320 as stated on the Sonar Emma plugin page.
I downloaded the 2.1.5320 version of Emma, replaced both emma.jar as well as emma_ant.jar in my Ant lib directory. After a clean re-compile and test, I was able to re-run the Sonar Ant task and have my code coverage reflected on Sonar.
The property 'sonar.surefire.reportsPath' needs to be defined before the definition of the sonar target.
The following definition gets the test info exported (although it's still not exporting coverage info):
<property name='sonar.surefire.reportsPath' value='${test.dir}'/>
<property name='sonar.dynamicAnalysis' value='reuseReports'/>
<property name='sonar.emma.reportPath' value='${coverage.report.dir}'/>
<target name='sonar'>
<property name='sonar.sources' value='${src.dir}'/>
<property name='sonar.tests' value='${test.src.dir}'/>
<property name='sonar.binaries' value='${build.dir}'/>
<path id='jars'>
<fileset dir='${env.JAVA_HOME}/jre/lib' includes='*.jar'/>
<fileset dir='${ivy.lib.dir}/test' includes='*.jar'/>
</path>
<pathconvert property='sonar.libraries' refid='jars' pathsep=','/>
<exec executable='p4' outputproperty='p4.P4CLIENT'>
<arg value='set'/>
<arg value='P4CLIENT'/>
</exec>
<propertyregex
property='p4client'
input='${p4.P4CLIENT}'
regexp='P4CLIENT=([^ ]+) *.*'
replace='\1'/>
<propertyregex
property='sonar.timestamp'
input='${build.time}'
regexp='_'
replace='T'/>
<sonar:sonar key='com.netflix:${module.name}' version='${p4client}#${sonar.timestamp}' xmlns:sonar='antlib:org.sonar.ant'/>
</target>

Resources