1

I am running Java code changeset in liquibase. But I am facing this issue where I am getting ClassNotFoundException.I did some searching around but could not find anything helpful. Alltough some research at this link was useful. I am using liquibase-core-2.0.1.


Below is my Changeset

<changeSet id="111" author="myname" >
        <customChange class="com.example.CreateTableTask">
        </customChange>
</changeSet>

Below is my java class

public class CreateTableTask implements CustomTaskChange
{
    private static Logger log = Logger.getLogger(CreateTableTask.class.getName());
    @Override
    public void execute(Database database) throws CustomChangeException
    {
        System.out.print("testsomestring");
        try
        {
            JdbcConnection databaseConnection = (JdbcConnection) database.getConnection();
            log.info("testsomestring");
        }
        catch (Exception e)
        {
            throw new CustomChangeException(e);
        }
    }

    @Override
    public String getConfirmationMessage()
    {
        return null;
    }

    @Override
    public void setUp() throws SetupException
    {

    }

    @Override
    public void setFileOpener(ResourceAccessor resourceAccessor)
    {

    }

    @Override
    public ValidationErrors validate(Database database)
    {
        return null;
    }
}

Below is the exception I am getting

java.lang.ClassNotFoundException: com.example.CreateTableTask liquibase.exception.ChangeLogParseException: Invalid Migration File: java.lang.ClassNotFoundException: com.example.CreateTableTask at liquibase.parser.core.xml.XMLChangeLogSAXParser.parse(XMLChangeLogSAXParser.java:132) at liquibase.Liquibase.update(Liquibase.java:107) at liquibase.integration.commandline.Main.doMigration(Main.java:825) at liquibase.integration.commandline.Main.main(Main.java:134) Caused by: org.xml.sax.SAXException: java.lang.ClassNotFoundException: com.example.CreateTableTask liquibase.exception.CustomChangeException: java.lang.ClassNotFoundException: com.example.CreateTableTask at liquibase.parser.core.xml.XMLChangeLogSAXHandler.startElement(XMLChangeLogSAXHandler.java:478) at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509) at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:749) at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:379) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2786) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606) at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:117) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777) at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141) at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213) at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:648) at liquibase.parser.core.xml.XMLChangeLogSAXParser.parse(XMLChangeLogSAXParser.java:98)

2
  • What command did you use to start Liquibase, and where is the jar file containing your custom code? The way that it should work is that Liquibase will scan the classpath for the class mentioned. You can give liquibase.bat (or liquibase.sh) an argument to specify a classpath, or Liquibase will look in its lib directory by default, if I recall correctly. That is a very old version of Liquibase, so if you can upgrade you probably should. Commented Nov 9, 2015 at 22:49
  • Thanks @SteveDonie .. Update is tjhe command I am using for liquibase.. what was missing is argument to specify a classpath .. Its resolved now.. Can you place the comment as answer I would accept it.. Commented Nov 10, 2015 at 6:32

1 Answer 1

0

What command did you use to start Liquibase, and where is the jar file containing your custom code?

The way that it should work is that Liquibase will scan the classpath for the class mentioned. You can give liquibase.bat (or liquibase.sh) an argument to specify a classpath, or Liquibase will look in its lib directory by default, if I recall correctly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.