I am working with Liquibase on Linux, does anyone know how to run the datbasechangelog.xml file from the Linux prompt step by step? And what's the idea behind databasechangelog and how it works?
For our projects, we have set up ant tasks to do this. So, for example, if you want to run the migrations, the ant file may look like the following:
ant-migrations.xml
<project name="Migrations" basedir="." default="update-database">
<property file="./liquibasetasks.properties" />
<path id="master-classpath" description="Master classpath">
<fileset dir="..\lib">
<include name="*.jar" />
</fileset>
</path>
<target name="update-database">
<fail unless="db.changelog.file">db.changelog.file not set</fail>
<fail unless="database.url">database.url not set</fail>
<fail unless="database.username">database.username not set</fail>
<fail unless="database.password">database.password not set</fail>
<taskdef resource="liquibasetasks.properties">
<classpath refid="master-classpath"/>
</taskdef>
<updateDatabase
changeLogFile="${db.changelog.file}"
driver="${database.driver}"
url="${database.url}"
username="${database.username}"
password="${database.password}"
promptOnNonLocalDatabase="${prompt.user.if.not.local.database}"
dropFirst="false"
classpathref="master-classpath"
/>
</target></project>
Make sure your liquibase jar file(s) are referenced in the classpath element.
The properties file contains the references that are particular to your environment:
liquibasetasks.properties
db.changelog.file=YOUR_MIGRATION_FILE.xml
#################################
## DB Settings
#################################
database.driver=
database.username=
database.password=
database.url=
Ok, so now we have the ant task set up and configured.. with all of that saved, you should be able to run the migration by typing the following at the command prompt:
linux>ant -f ant-migrations.xml update-database
Hope that helps!
Related
I use Sonar 4.1.1, Jboss 6.x, Jacoco 0.6.4, execute tasks with Ant I am not allowed to use Maven. In an eclipse workspace, I have two projects, one is the web application another is selenium test.
I am able to get unit test and code coverage for unit test. But sonar is not able to read the integration test file created by Jacoco. I think there might be something wrong with the way I create jacoco-it.exec file so sonar can't read it. Because sonar does read my jacoco-ut.exec file. And I am able to have both reportPath and itReportPath to read my jacoco-ut.exec file with no problem. Also thinking maybe is something wrong in my build file. I did a lot of research and tried many different ways to create the jacoco-it.exec file, different Jacoco settings and followed different examples from sonar, jacoco, other blogs but still doesn't work. I must be missing something Help!! Thanks!!
I have VM arguments for Jboss like this
-javaagent:/path to jar/jacocoagent.jar=destfile=/path for create/jacoco-it.exec
When I run selenium, the above code create a file with some data, size about 1.3MB
Here is the part of build relate to this issue
<property name="sonar.sourceEncoding" value="UTF-8" />
<property name="sonar.java.coveragePlugin" value="jacoco" />
<property name="sonar.core.codeCoveragePlugin" value="jacoco" />
<property name="sonar.dynamicAnalysis" value="reuseReports" />
<property name="sonar.jacoco.reportsPath" value="${reports.dir}/junit" />
<property name="sonar.jacoco.itReportPath" value="${reports.dir}/jacoco-it.exec" />
<property name="sonar.jacoco.reportPath" value="${reports.dir}/jacoco-ut.exec" />
<target name="unitTest" depends="compile">
<taskdef name="junit" classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask">
<classpath>
<path refid="classpath"/>
</classpath>
</taskdef>
<!-- Import the JaCoCo Ant Task -->
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath refid="classpath"/>
</taskdef>
<!-- Run your unit tests, adding the JaCoCo agent -->
<jacoco:coverage destfile="reports/jacoco-ut.exec" xmlns:jacoco="antlib:org.jacoco.ant">
<junit printsummary="yes" haltonfailure="yes" forkmode="once" fork="true" dir="${basedir}" failureProperty="test.failed">
<classpath location="${classes.dir}" />
<classpath refid="classpath"/>
<formatter type="plain" />
<formatter type="xml" />
<batchtest fork="true" todir="${reports.junit.xml.dir}">
<fileset dir="src">
<include name="**/*TestAdd.java" />
</fileset>
</batchtest>
</junit>
</jacoco:coverage>
</target>
<target name="coverageTest" depends="compile">
<taskdef name="junit" classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask">
<classpath>
<path refid="classpath"/>
</classpath>
</taskdef>
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath refid="classpath"/>
</taskdef>
<!--Run your unit tests, adding the JaCoCo agent-->
<jacoco:coverage xmlns:jacoco="antlib:org.jacoco.ant" dumponexit="true" >
<junit printsummary="yes" haltonfailure="yes" forkmode="once" fork="true" dir="${basedir}" failureProperty="test.failed">
<classpath location="${classes.dir}"/>
<classpath refid="classpath"/>
<formatter type="plain" />
<formatter type="xml" />
<formatter type="plain" usefile="false"/>
<batchtest todir="${reports.junit.xml.dir}">
<fileset dir="../HelloAppTest/src">
<include name="**/answerTest.java"/>
</fileset>
</batchtest>
</junit>
</jacoco:coverage>
</target>
The reason for that is, may be you are NOT attaching Jacocoagent.jar file to the "TARGET" (ex: JBoss / Tomcat) JVM's scope and stopping it so that it can flush the final code coverage data to the jacoco it exec file.
Once you do that (instead of using Maven/ANT's JVM scope), run your non-Unit (IT) tests and then STOP the target JVM.
After the target JVM is stopped, you'll get the final jacoco .exec file genreated for the IT tests. Use that file for sonar.jacoco.itReportPath variable and it'll work.
For ex: I pass/have this variable to the Tomcat's startup.sh script and while starting tomcat (target JVM), I use this variable within the Tomcat's actual start command.
PROJ_EXTRA_JVM_OPTS=-javaagent:tomcat/jacocoagent.jar=destfile=build/jacoco/IT/jacocoIT.exec,append=false
I would like to specify the classpath for an fpt task directly in my Ant Build script. I tried the following:
<target name="ftp-upload" depends="build-html">
<echo message="Ftp upload started with user ${user}" />
<ftp verbose="yes"
remotedir="${ftp.dir}"
server="${server}"
userid="${user}"
password="${password}"
depends="yes">
<fileset dir="${mystuff.dir}/.." />
<classpath refid="build.classpath" />
</ftp>
</target>
and
<target name="ftp-upload" depends="build-html">
<echo message="Ftp upload started with user ${user}" />
<ftp verbose="yes"
remotedir="${ftp.dir}"
server="${server}"
userid="${user}"
password="${password}"
depends="yes"
classpathref="build.classpath"
>
<fileset dir="${mystuff.dir}/.." />
</ftp>
</target>
The first approach gives me the following error message:
Could not create type ftp due to java.lang.NoClassDefFoundError: org/apache/commons/net/ftp/FTPClientConfig
The second approach gives me the following error message:
ftp doesn't support the "classpathref" attribute
Is it possible to set the classpath in the build script for the ftp tasks or do I have to do it outside the build script on my server? Would be nice to have the build script self-contained.
Solution:
Just re-define the ftp task with your classpath reference:
<taskdef name="ftp" classname="org.apache.tools.ant.taskdefs.optional.net.FTP">
<classpath>
<pathelement location="\lib\commons-net-1.4.0.jar"/>
</classpath>
</taskdef>
Have you tried the solution commented at How to load an optional task into ant without -lib or global installation? ?
I had a similar problem some time ago and I solved it adding a new classloader.
Regards
I would like to generate SQL DDL scripts from Hibernate/JPA Annotation Classes using ANT.
Below is the ANT script that I wrote based on Hibernate Dev Docs URL: http://docs.jboss.org/hibernate/orm/4.1/devguide/en-US/html_single/
<project name="yourmarketnet" default="all" basedir=".">
<target name="ddl_generation">
<!-- paths to required jars -->
<path location="web/WEB-INF/lib/hibernate-annotations.jar" />
<path location="web/WEB-INF/lib/ejb3-persistence.jar" />
<path location="web/WEB-INF/lib/hibernate-entitymanager.jar" />
<path location="web/WEB-INF/lib/javaassist.jar" />
<path location="web/WEB-INF/lib/hibernate-tools.jar"/>
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask.jar">
<classpath path="${build.dir}/web/WEB-INF/lib/hibernate-tools.jar"/>
</taskdef>
<!-- output destination -->
<hibernatetool destdir="${build.dir}">
<!-- were the annotation beans files are located-->
<classpath>
<path location="${build.dir}/web/WEB-INF/classes/com/yourmarketnet/beans" />
</classpath>
<!-- list exporters here -->
<hbm2ddl
export="false"
update="false"
drop="true"
create="true"
outputfilename="myApps.ddl"
delimiter=";"
format="false"
haltonerror="true"/>
</hibernatetool>
</target>
</project>
Im getting ERROR taskdef class org.hibernate.tool.ant.HibernateToolTask cannot be found
using the classloader AntClassLoader[]
I also checked to see if hibernate-tools.jar was actually in the path and it was (C:\Users\naim\Documents\NetBeansProjects\yourmarketnet\build\web\WEB-INF\lib\hibernate-tools.jar)
Can someone please tell me step by step how to fix/debug this issue , thanks.
Error message clearly tells you that ant can't find your tools. When you declare
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" >
<classpath path="${build.dir}/web/WEB-INF/lib"/>
</taskdef>
it's already wrong because tool classes are not in directory but in jar. Secondly, your intent seems to be to use ${build.dir} as output location, so why would it contain tool classes? Anyway, you didn't even define this directory.
So if you really have your hibernate-tools.jar in web/WEB-INF/lib, you probably want something like
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" >
<classpath path="web/WEB-INF/lib/hibernate-tools.jar"/>
</taskdef>
Note that it's relative to your project directory.
This is driving me crazy and I'm shocked that official documentation is absolutely useles.
Here is what I have:
IntelliJ IDEA 11
OpenJPA 2.1.1
Since openjpa is added into list of used libraries I already had classpath to OpenJPA which looks like this
<path id="library.openjpa.classpath">
<fileset dir="${basedir}/lib/openjpa">
<patternset refid="library.patterns"/>
</fileset>
</path>
According to official documentation I added following target
<target name="enhance">
<copy includeemptydirs="false" todir="${basedir}/lib/openjpa">
<fileset dir="src" excludes="**/*.launch, **/*.java"/>
</copy>
<taskdef name="openjpac" classname="org.apache.openjpa.ant.PCEnhancerTask">
<classpath refid="library.openjpa.classpath"/>
</taskdef>
<openjpac>
<classpath refid="library.openjpa.classpath"/>
</openjpac>
</target>
It gives me exception
C:\work\prj\build.xml:283: org.apache.openjpa.util.MetaDataException:
MetaDataFactory could not be configured
(conf.newMetaDataFactoryInstance() returned null). This might mean
that no configuration properties were found. Ensure that you have a
META-INF/persistence.xml file, that it is available in your classpath,
or that the properties file you are using for configuration is
available. If you are using Ant, please see the or
attributes of the task's nested element.
This can also occur if your OpenJPA distribution jars are corrupt, or
if your security policy is overly strict.
I tested with Process Monitor and can see that it opens and reads persistence.xml.
Some person filed bug having problems I have and the answer he got was that finding persistence.xml is not a source of problem.
Questions are:
What can I do to make it work ?
Can I make it work by skipping need for persistence.xml and just specifying pattern for .class files I want to be enhanced ?
It's more Ant question. How can I make OpenJPA enhancer to look for persistence.xml in directory other than where openjpa-2.1.1.jar resides ?
So I couldn't make it work without undocumented propertiesFile. Here is version that works for me. Also specifying persistence-unit via # makes it fail with NullReferenceException.
<target name="enhance">
<taskdef name="openjpac" classname="org.apache.openjpa.ant.PCEnhancerTask">
<classpath refid="library.openjpa.classpath"/>
</taskdef>
<openjpac>
<classpath refid="library.openjpa.classpath"/>
<classpath location="${reporting.output.dir}"/>
<config propertiesFile = "${basedir}/src/META-INF/persistence.xml"/>
</openjpac>
</target>
It appears that you might have missed an important part from the documentation. Your library.openjpa.classpath is missing a reference to your Entities, and the location of the persistence.xml file. Try adding that and see how it goes.
<path id="jpa.enhancement.classpath">
<pathelement location="bin"/> <!-- add something like this -->
<!-- lib contains all of the jars that came with the OpenJPA binary download -->
<fileset dir="lib">
<include name="**/*.jar"/>
</fileset>
</path>
1.I am getting below errror while executing batch file in cruise control:
<exception><![CDATA[ThoughtWorks.CruiseControl.Core.Tasks.BuilderException: Command Line Build timed out (after 600 seconds)
code which i used is
<exec>
<executable>D:\DITBUILT.bat</executable>
</exec>
2.I want to publish in different folder using cruise control.. I am using the code... I am not able to publish in different folder
<executable>C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe</executable>
<workingDirectory>D:\Cas_CC\SourceCode\PolandSME-MAIN\SRC\UI</workingDirectory>
<projectFile>CAS.sln</projectFile>
<buildArgs> /p:Configuration=Release /p:Platform="Any CPU" </buildArgs>
<targets>Build</targets>
<logger>ThoughtWorks.CruiseControl.MsBuild.XmlLogger,D:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll</logger>
Please help me out
how to publish in different folder using cruise control
how to execute a batch file using cruise control...
Thanks in advance
The error you are getting with the batch file might be resolved by using cmd.exe as executable and "/c D:\DITBUILT.bat" as arguments?
I would recommend using cruise control with NANT.
<tasks>
<nant>
<executable>C:\Nant\Nant0.86\bin\nant.exe</executable>
<baseDirectory>.</baseDirectory>
<buildFile>C:\NANT_SCRIPTS\build.xml</buildFile>
<targetList>
<target>YourProject_Publish</target>
</targetList>
<buildTimeoutSeconds>2000</buildTimeoutSeconds>
</nant>
</tasks>
In your build.xml file you can use NANT commands to execute your bat files or pretty much do anything else. It supports the 3.5 framework as well.
<exec program="C:\NANT_SCRIPTS\publish\YourProject.bat" />
<delete dir="${web01}\yourSite.com\WebFolder" />
<copy todir="${web01}\yourSite.com\WebFolder" >
<fileset basedir="C:\CruiseControl\ProjectFolders\YourProject\Website" >
<include name="*.aspx" />
<include name="*.config" />
<include name="*.master" />
<include name="*.asax" />
<include name="*.ascx" />
<include name="*.sitemap" />
</fileset>
</copy>