Very strange 'could not find implementation of liquibase.logging.logger.'

Hello everyone!

I am working in Netbeans 7.2. My java project is using maven to build one-jar file. I added liquibase as a dependency in pom.xml:
       
            org.liquibase
            liquibase-core
            2.0.1
       

I made a function that before application start does upgrade database. Here is required code:

  1. private static class ChangeLogClassLoader extends ClassLoader {

            private final String changeLogFile;
           
            public ChangeLogClassLoader(String changeLogFile) {
                this.changeLogFile = changeLogFile;
            }


            @Override
            public InputStream getResourceAsStream(String string) {
                InputStream is = getClass().getResourceAsStream(changeLogFile);
                return is;
            }
        }

        private void makeDatabasePatch() throws DatabaseException, LiquibaseException {
            //create datbase
            String filePath = “/changelog.xml”;
            Database database = DatabaseFactory.getInstance().
                    findCorrectDatabaseImplementation(new JdbcConnection(connection));
            database.setDefaultSchemaName(“LOGGER”);
           
            ResourceAccessor fileAccessor = new FileSystemResourceAccessor();
            ResourceAccessor classLoaderAccessor = new ClassLoaderResourceAccessor(
                    new ChangeLogClassLoader(filePath));
            ResourceAccessor compositeAccessor = new CompositeResourceAccessor(classLoaderAccessor, fileAccessor);
           
            Liquibase liquiBase = new Liquibase(filePath, compositeAccessor, database);
            liquiBase.update(null);
  2. }

When i launch my application via NetBeans - it starts very well and does upgrade. But if i launch via cmd like ‘java -jar MyApp.one-jar.jar’ then i take expections:

  1. Exception in thread “main” java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at com.simontuffs.onejar.Boot.run(Boot.java:340)
        at com.simontuffs.onejar.Boot.main(Boot.java:166)
    Caused by: liquibase.exception.ServiceNotFoundException: liquibase.exception.ServiceNotFoundException: liquibase.exception.ServiceNotFoundException: Could not find implementation of liquibase.logging.Logger
        at liquibase.logging.LogFactory.getLogger(LogFactory.java:19)
        at liquibase.logging.LogFactory.getLogger(LogFactory.java:30)
        at liquibase.database.DatabaseFactory.findCorrectDatabaseImplementation(DatabaseFactory.java:67)
        … 12 more
    Caused by: liquibase.exception.ServiceNotFoundException: liquibase.exception.ServiceNotFoundException: Could not find implementation of liquibase.logging.Logger
        at liquibase.servicelocator.ServiceLocator.newInstance(ServiceLocator.java:160)
        at liquibase.logging.LogFactory.getLogger(LogFactory.java:17)
        … 18 more
    Caused by: liquibase.exception.ServiceNotFoundException: Could not find implementation of liquibase.logging.Logger
        at liquibase.servicelocator.ServiceLocator.findClass(ServiceLocator.java:126)
        at liquibase.servicelocator.ServiceLocator.newInstance(ServiceLocator.java:158)
        … 19 more

Also, i used compiled liquibase jar file and it worked fine with my database.

Can anyone help me?

Also, i found that class loaders are different when jar launches from NetBeans or cmd. Built one-jar uses own class loader.