在liquibase

时间:2015-11-09 10:36:05

标签: java liquibase

我在liquibase中运行Java代码更改集。但我正面临这个问题,我得到了ClassNotFoundException。我做了一些搜索,但找不到任何有用的东西。尽管 this link 的一些研究很有用。我正在使用liquibase-core-2.0.1。


以下是我的变更集

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

以下是我的java类

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;
    }
}

以下是我得到的例外

  

java.lang.ClassNotFoundException:com.example.CreateTableTask   liquibase.exception.ChangeLogParseException:无效的迁移文件:   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)引起: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)           在com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)           在com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)           在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)

1 个答案:

答案 0 :(得分:0)

您使用什么命令启动Liquibase,包含自定义代码的jar文件在哪里?

它应该工作的方式是Liquibase将扫描所提到的类的类路径。你可以给liquibase.bat(或liquibase.sh)一个参数来指定一个类路径,或者如果我没记错的话,Liquibase会默认查看它的lib目录。