Re: Loading cayenne mapped class from URLClassLoader

From: rigel (zetata..mail.com)
Date: Mon Nov 24 2008 - 15:05:16 EST

  • Next message: Scott Anderson: "RE: Loading cayenne mapped class from URLClassLoader"

    Hi Andrus, first of all thank you for your great work :clap: .

    Andrus Adamchik wrote:
    >
    > Hi, could you possibly try it with Cayenne 3.0M4? I think it should
    > already be fixed there.
    >

    Yes of course, I try to put my small contribute for what I can.

    This is the output (JDBC driver is the only jar pre-loaded into classpath
    because differently by Cayenne 2 now (DriverDataSource.java:62) does not
    solve the
    class driver):

    Loading lib: http://localhost:80/users/antares/libs/ashwood-2.0.jar
    Loading lib: http://localhost:80/users/antares/libs/asm-3.0.jar
    Loading lib: http://localhost:80/users/antares/libs/asm-commons-3.0.jar
    Loading lib:
    http://localhost:80/users/antares/libs/commons-collections-3.1.jar
    Loading lib: http://localhost:80/users/antares/libs/commons-logging-1.1.jar
    Loading lib:
    http://localhost:80/users/antares/libs/geronimo-jpa_3.0_spec-1.0.jar
    Loading lib: http://localhost:80/users/antares/libs/velocity-1.3.jar
    Loading lib: http://localhost:80/users/antares/libs/cayenne-agent-3.0M4.jar
    Loading lib: http://localhost:80/users/antares/libs/cayenne-client-3.0M4.jar
    Loading lib:
    http://localhost:80/users/antares/libs/cayenne-modeler-3.0M4.jar
    Loading lib: http://localhost:80/users/antares/libs/cayenne-server-3.0M4.jar
    Loading lib: http://localhost:80/users/antares/libs/w3d-base.jar
    Loading lib: http://localhost:80/users/antares/libs/w3d-orm.jar
    24-nov-2008 20.20.13 org.apache.cayenne.conf.RuntimeLoadDelegate
    startedLoading
    INFO: started configuration loading.
    24-nov-2008 20.20.13 org.apache.cayenne.conf.RuntimeLoadDelegate
    shouldLoadDataDomain
    INFO: loaded domain: dbw3d
    24-nov-2008 20.20.13 org.apache.cayenne.conf.RuntimeLoadDelegate loadDataMap
    INFO: loaded .
    24-nov-2008 20.20.13 org.apache.cayenne.conf.RuntimeLoadDelegate
    shouldLoadDataNode
    INFO: loading .
    24-nov-2008 20.20.13 org.apache.cayenne.conf.RuntimeLoadDelegate
    shouldLoadDataNode
    INFO: using factory: org.apache.cayenne.conf.DriverDataSourceFactory
    24-nov-2008 20.20.13 org.apache.cayenne.conf.DriverDataSourceFactory load
    INFO: loading driver information from 'dbw3dNode.driver.xml'.
    24-nov-2008 20.20.13
    org.apache.cayenne.conf.DriverDataSourceFactory$DriverHandler init
    INFO: loading driver org.postgresql.Driver
    24-nov-2008 20.20.13
    org.apache.cayenne.conf.DriverDataSourceFactory$LoginHandler init
    INFO: loading user name and password.
    java.lang.ClassNotFoundException:
    org.apache.cayenne.conf.PlainTextPasswordEncoder
            at java.net.URLClassLoader$1.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at
    org.apache.cayenne.conn.DataSourceInfo.getPasswordEncoder(DataSourceInfo.java:207)
            at
    org.apache.cayenne.conf.DriverDataSourceFactory$LoginHandler.init(DriverDataSourceFactory.java:324)
            at
    org.apache.cayenne.conf.DriverDataSourceFactory$DriverHandler.startElement(DriverDataSourceFactory.java:191)
            at
    com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
    Source)
            at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown
    Source)
            at
    org.apache.cayenne.conf.DriverDataSourceFactory.load(DriverDataSourceFactory.java:130)
            at
    org.apache.cayenne.conf.DriverDataSourceFactory.getDataSource(DriverDataSourceFactory.java:78)
            at
    org.apache.cayenne.conf.RuntimeLoadDelegate.shouldLoadDataNode(RuntimeLoadDelegate.java:299)
            at
    org.apache.cayenne.conf.ConfigLoader$NodeHandler.init(ConfigLoader.java:337)
            at
    org.apache.cayenne.conf.ConfigLoader$DomainHandler.startElement(ConfigLoader.java:223)
            at
    com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
    Source)
            at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown
    Source)
            at
    com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown
    Source)
            at org.apache.cayenne.conf.ConfigLoader.loadDomains(ConfigLoader.java:79)
            at
    org.apache.cayenne.conf.DefaultConfiguration.initialize(DefaultConfiguration.java:164)
            at
    org.apache.cayenne.conf.Configuration.initializeSharedConfiguration(Configuration.java:157)
            at
    org.apache.cayenne.conf.Configuration.initializeSharedConfiguration(Configuration.java:139)
            at
    org.apache.cayenne.conf.Configuration.initializeSharedConfiguration(Configuration.java:119)
            at
    org.apache.cayenne.conf.Configuration.getSharedConfiguration(Configuration.java:89)
            at
    org.apache.cayenne.access.DataContext.createDataContext(DataContext.java:162)
            at it.wipidea.w3d.SomeClass.init(SomeClass.java:42)
            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 NetLoader.start(NetLoader.java:65)
            at NetLoader.main(NetLoader.java:76)
    24-nov-2008 20.20.13 org.apache.cayenne.access.QueryLogger logPoolCreated
    INFO: Created connection pool: jdbc:postgresql://localhost/w3d
            Driver class: org.postgresql.Driver
            Min. connections in the pool: 1
            Max. connections in the pool: 1
    24-nov-2008 20.20.13 org.apache.cayenne.conf.RuntimeLoadDelegate
    shouldLoadDataNode
    INFO: loaded datasource.
    24-nov-2008 20.20.13 org.apache.cayenne.conf.RuntimeLoadDelegate initAdapter
    INFO: no adapter set, using automatic adapter.
    24-nov-2008 20.20.13 org.apache.cayenne.conf.RuntimeLoadDelegate
    shouldLinkDataMap
    INFO: loaded map-ref: dbw3dMap.
    24-nov-2008 20.20.13 org.apache.cayenne.conf.RuntimeLoadDelegate
    finishedLoading
    INFO: finished configuration loading in 142 ms.
    24-nov-2008 20.20.13 org.apache.cayenne.access.QueryLogger logQueryStart
    INFO: --- will run 1 query.
    24-nov-2008 20.20.13 org.apache.cayenne.access.QueryLogger logConnect
    INFO: Opening connection: jdbc:postgresql://localhost/w3d
            Login: postgres
            Password: *******
    24-nov-2008 20.20.13 org.apache.cayenne.access.QueryLogger logConnectSuccess
    INFO: +++ Connecting: SUCCESS.
    24-nov-2008 20.20.13 org.apache.cayenne.access.QueryLogger
    logBeginTransaction
    INFO: --- transaction started.
    24-nov-2008 20.20.13 org.apache.cayenne.access.QueryLogger log
    INFO: Detected and installed adapter:
    org.apache.cayenne.dba.postgres.PostgresAdapter
    24-nov-2008 20.20.13 org.apache.cayenne.access.QueryLogger logQueryError
    INFO: *** error.
    java.lang.ClassNotFoundException: it.weev.orm.cayenne.dbw3d.matlibs
            at java.net.URLClassLoader$1.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClassInternal(Unknown Source)
            at java.lang.Class.forName0(Native Method)
            at java.lang.Class.forName(Unknown Source)
            at org.apache.cayenne.util.Util.getJavaClass(Util.java:589)
            at org.apache.cayenne.map.ObjEntity.getJavaClass(ObjEntity.java:271)
            at
    org.apache.cayenne.reflect.PersistentDescriptorFactory.getDescriptor(PersistentDescriptorFactory.java:57)
            at
    org.apache.cayenne.reflect.ClassDescriptorMap.createDescriptor(ClassDescriptorMap.java:129)
            at
    org.apache.cayenne.reflect.LazyClassDescriptorDecorator.checkDescriptorInitialized(LazyClassDescriptorDecorator.java:51)
            at
    org.apache.cayenne.reflect.LazyClassDescriptorDecorator.getEntity(LazyClassDescriptorDecorator.java:75)
            at
    org.apache.cayenne.access.trans.SelectTranslator.appendQueryColumns(SelectTranslator.java:267)
            at
    org.apache.cayenne.access.trans.SelectTranslator.buildResultColumns(SelectTranslator.java:240)
            at
    org.apache.cayenne.access.trans.SelectTranslator.createSqlString(SelectTranslator.java:103)
            at
    org.apache.cayenne.dba.postgres.PostgresSelectTranslator.createSqlString(PostgresSelectTranslator.java:32)
            at
    org.apache.cayenne.access.trans.QueryAssembler.createStatement(QueryAssembler.java:116)
            at
    org.apache.cayenne.access.jdbc.SelectAction.performAction(SelectAction.java:72)
            at
    org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:58)
            at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:230)
            at
    org.apache.cayenne.access.DataDomainQueryAction.runQuery(DataDomainQueryAction.java:424)
            at
    org.apache.cayenne.access.DataDomainQueryAction.access$000(DataDomainQueryAction.java:68)
            at
    org.apache.cayenne.access.DataDomainQueryAction$2.transform(DataDomainQueryAction.java:397)
            at
    org.apache.cayenne.access.DataDomain.runInTransaction(DataDomain.java:847)
            at
    org.apache.cayenne.access.DataDomainQueryAction.runQueryInTransaction(DataDomainQueryAction.java:394)
            at
    org.apache.cayenne.access.DataDomainQueryAction.execute(DataDomainQueryAction.java:120)
            at org.apache.cayenne.access.DataDomain.onQuery(DataDomain.java:740)
            at
    org.apache.cayenne.util.ObjectContextQueryAction.runQuery(ObjectContextQueryAction.java:317)
            at
    org.apache.cayenne.util.ObjectContextQueryAction.execute(ObjectContextQueryAction.java:96)
            at org.apache.cayenne.access.DataContext.onQuery(DataContext.java:1336)
            at
    org.apache.cayenne.access.DataContext.performQuery(DataContext.java:1325)
            at it.wipidea.w3d.SomeClass.init(SomeClass.java:45)
            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 NetLoader.start(NetLoader.java:65)
            at NetLoader.main(NetLoader.java:76)
    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 NetLoader.start(NetLoader.java:65)
            at NetLoader.main(NetLoader.java:76)
    Caused by: org.apache.cayenne.CayenneRuntimeException: [v.3.0M4 May 18 2008
    15:29:33] Query exception.
            at
    org.apache.cayenne.access.DataDomainQueryAction.nextQueryException(DataDomainQueryAction.java:551)
            at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:237)
            at
    org.apache.cayenne.access.DataDomainQueryAction.runQuery(DataDomainQueryAction.java:424)
            at
    org.apache.cayenne.access.DataDomainQueryAction.access$000(DataDomainQueryAction.java:68)
            at
    org.apache.cayenne.access.DataDomainQueryAction$2.transform(DataDomainQueryAction.java:397)
            at
    org.apache.cayenne.access.DataDomain.runInTransaction(DataDomain.java:847)
            at
    org.apache.cayenne.access.DataDomainQueryAction.runQueryInTransaction(DataDomainQueryAction.java:394)
            at
    org.apache.cayenne.access.DataDomainQueryAction.execute(DataDomainQueryAction.java:120)
            at org.apache.cayenne.access.DataDomain.onQuery(DataDomain.java:740)
            at
    org.apache.cayenne.util.ObjectContextQueryAction.runQuery(ObjectContextQueryAction.java:317)
            at
    org.apache.cayenne.util.ObjectContextQueryAction.execute(ObjectContextQueryAction.java:96)
            at org.apache.cayenne.access.DataContext.onQuery(DataContext.java:1336)
            at
    org.apache.cayenne.access.DataContext.performQuery(DataContext.java:1325)
            at it.wipidea.w3d.SomeClass.init(SomeClass.java:45)
            ... 6 more
    Caused by: java.lang.ClassNotFoundException:
    it.weev.orm.cayenne.dbw3d.matlibs
            at java.net.URLClassLoader$1.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClassInternal(Unknown Source)
            at java.lang.Class.forName0(Native Method)
            at java.lang.Class.forName(Unknown Source)
            at org.apache.cayenne.util.Util.getJavaClass(Util.java:589)
            at org.apache.cayenne.map.ObjEntity.getJavaClass(ObjEntity.java:271)
            at
    org.apache.cayenne.reflect.PersistentDescriptorFactory.getDescriptor(PersistentDescriptorFactory.java:57)
            at
    org.apache.cayenne.reflect.ClassDescriptorMap.createDescriptor(ClassDescriptorMap.java:129)
            at
    org.apache.cayenne.reflect.LazyClassDescriptorDecorator.checkDescriptorInitialized(LazyClassDescriptorDecorator.java:51)
            at
    org.apache.cayenne.reflect.LazyClassDescriptorDecorator.getEntity(LazyClassDescriptorDecorator.java:75)
            at
    org.apache.cayenne.access.trans.SelectTranslator.appendQueryColumns(SelectTranslator.java:267)
            at
    org.apache.cayenne.access.trans.SelectTranslator.buildResultColumns(SelectTranslator.java:240)
            at
    org.apache.cayenne.access.trans.SelectTranslator.createSqlString(SelectTranslator.java:103)
            at
    org.apache.cayenne.dba.postgres.PostgresSelectTranslator.createSqlString(PostgresSelectTranslator.java:32)
            at
    org.apache.cayenne.access.trans.QueryAssembler.createStatement(QueryAssembler.java:116)
            at
    org.apache.cayenne.access.jdbc.SelectAction.performAction(SelectAction.java:72)
            at
    org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:58)
            at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:230)
            ... 18 more

    This is my netloader code:

    import java.lang.reflect.Method;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.URLClassLoader;
    import java.util.Enumeration;
    import java.util.Iterator;
    import java.util.ResourceBundle;
    import java.util.TreeMap;

    public final class NetLoader {

            final static private ResourceBundle RB;
            static {
                    RB = ResourceBundle.getBundle(
                                    //"loader-2_0_4"
                                    "loader-3_M4"
                                    );
            }
            
            private URL[] libUrls;
            
            public NetLoader() {
                    this.initLibrary();
            }
            
            private void initLibrary() {
                    TreeMap libs = new TreeMap();
                    Enumeration en = RB.getKeys();
                    while (en.hasMoreElements()) {
                            String key = en.nextElement();
                            libs.put(key,RB.getString(key).split(","));
                    }
                    libUrls = new URL[libs.size()];
                    Iterator it = libs.keySet().iterator();
                    int idx = 0;
                    while (it.hasNext()) {
                            String key = it.next();
                            URL url = null;
                            try {
                                    url = new URL(libs.get(key)[0],libs.get(key)[1],libs.get(key)[2]);
                            } catch (MalformedURLException e) {
                                    System.err.println(e.getMessage());
                                    System.exit(1);
                            }
                            libUrls[idx++] = url;
                            int port = (url.getPort()==-1) ? 80 : url.getPort() ;
                            System.out.println("Loading lib: " +
    url.getProtocol()+"://"+url.getHost()+":"+port+url.getFile());
                    }

            }

            protected void start() {
                    URLClassLoader urlClassLoader = new URLClassLoader(libUrls,
                                    Thread.currentThread().getContextClassLoader()
                                    //ClassLoader.getSystemClassLoader()
                                    );
            
                    
                    try {
                            Class<?> clzz =
    Class.forName("it.wipidea.w3d.SomeClass",true,urlClassLoader);
                            //Class<?> clzz = urlClassLoader.loadClass("it.wipidea.w3d.SomeClass");
                            Method m = clzz.getDeclaredMethod("init", new Class[]{});
                            m.invoke(null, new Object[]{});
                    } catch (Throwable e) {
                            e.printStackTrace();
                    }
            }
            
            /**
             *..aram args
             */
            public static void main(String[] args) {
                    NetLoader netLoader = new NetLoader();
                    netLoader.start();
            }

    }

    And this is the property file used to load all libs:

    ## Cayenne III
    #libs.001 = http,localhost,/users/antares/libs/postgresql-8.2-504.jdbc4.jar
    libs.011 = http,localhost,/users/antares/libs/ashwood-2.0.jar
    libs.012 = http,localhost,/users/antares/libs/asm-3.0.jar
    libs.013 = http,localhost,/users/antares/libs/asm-commons-3.0.jar

    libs.014 = http,localhost,/users/antares/libs/commons-collections-3.1.jar
    libs.015 = http,localhost,/users/antares/libs/commons-logging-1.1.jar
    libs.016 = http,localhost,/users/antares/libs/geronimo-jpa_3.0_spec-1.0.jar
    libs.017 = http,localhost,/users/antares/libs/velocity-1.3.jar

    libs.021 = http,localhost,/users/antares/libs/cayenne-agent-3.0M4.jar
    libs.022 = http,localhost,/users/antares/libs/cayenne-client-3.0M4.jar
    libs.023 = http,localhost,/users/antares/libs/cayenne-modeler-3.0M4.jar
    libs.024 = http,localhost,/users/antares/libs/cayenne-server-3.0M4.jar

    libs.031 = http,localhost,/users/antares/libs/w3d-base.jar
    libs.032 = http,localhost,/users/antares/libs/w3d-orm.jar

    ## Cayenne II
    #libs.001 = http,localhost,/users/antares/libs/postgresql-8.2-504.jdbc4.jar
    #libs.011 = http,localhost,/users/antares/libs/cayenne-2_0_4-util.jar
    #libs.021 = http,localhost,/users/antares/libs/w3d-base.jar
    #libs.022 = http,localhost,/users/antares/libs/w3d-orm.jar

    Currently I am not able to pass all Maven test to build Cayenne,
    so I don't know if the "Class.forName(className)" allows the Util.class
    to solve all classes in the URLLoaderClasspath.

    Hoping can be useful, sorry for long long post :wistle: :-P.

    Best Regards.

    Andrus Adamchik wrote:
    >
    > Hi, could you possibly try it with Cayenne 3.0M4? I think it should
    > already be fixed there.
    >
    > Cheers,
    > Andrus
    >
    >
    >>
    >> --
    >> View this message in context:
    >> http://www.nabble.com/Loading-cayenne-mapped-class-from-URLClassLoader-tp20654024p20655214.html
    >> Sent from the Cayenne - User mailing list archive at Nabble.com.
    >
    >
    >

    -- 
    View this message in context: http://www.nabble.com/Loading-cayenne-mapped-class-from-URLClassLoader-tp20654024p20668667.html
    Sent from the Cayenne - User mailing list archive at Nabble.com.
    



    This archive was generated by hypermail 2.0.0 : Mon Nov 24 2008 - 15:05:52 EST