我正在liquibase中运行Java代码变更集。但我面临的问题是,我得到了ClassNotFoundException。我四处搜索了一下,但找不到任何有用的东西。Allhardy在这个链接上的一些研究是有用的。我使用的是液化核心-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.CreateTableTasklikibase.exception.ChangeLogParseException:无效的迁移文件:java.lang.ClassNotFoundException:com.example.CreateTableTask位于liquibase.parser.core.xml.XMLChangeLogSAXParser.parse(XMLChangeLogSAXParser.java:132)在利基巴斯。Liquibase.update(Liquibase.java:107)位于liquibase.integration.commandline.Main.doMigration(Main.java:825)在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位于liquibase.parser.core.xml.XMLChangeLogSAXHandler.startElement(XMLChangeLogSAXHandler.java:478)网址:com.sun.org/apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509)网址:com.sun.org/apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:749)网址:com.sun.org/apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:379)网址:com.sun.org/apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFractionScannerImpl.java:2786)网址:com.sun.org/apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScanner impl.java:606)网址:com.sun.org/apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:117)网址:com.sun.org/apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFractionScannerImpl.java:510)网址: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)网址:com.sun.org/apache.xerces.internal.jaxp.SAXParserImpl$JAXPSParser.parse(SAXParserImpl.java:648)在liquibase.parser.core.xml.XMLChangeLogSAXParser.parse(XMLChangeLogSAXParser.java:98)
您使用了什么命令来启动Liquibase,包含自定义代码的jar文件在哪里?
它的工作方式是Liquibase将扫描类路径中提到的类。您可以给liquibase.bat(或liquibase.sh)一个参数来指定类路径,或者如果我记得正确的话,liquibase默认情况下会在其lib目录中查找。